Author Topic: Ruby Discussion and Help  (Read 12323 times)

0 Members and 2 Guests are viewing this topic.

Ashbad

  • Guest
Re: Ruby Discussion and Help
« Reply #15 on: May 16, 2011, 06:19:50 pm »
well, it's more of me just practicing the use of lambda expressions :P

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: Ruby Discussion and Help
« Reply #16 on: May 16, 2011, 06:37:30 pm »
The only place that I heard about ruby was in RPG Maker XP
Sig wipe!

Ashbad

  • Guest
Re: Ruby Discussion and Help
« Reply #17 on: May 16, 2011, 06:40:54 pm »
The only place that I heard about ruby was in RPG Maker XP

how is it used there?  Just curious.
« Last Edit: May 16, 2011, 06:41:04 pm by Ashbad »

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: Ruby Discussion and Help
« Reply #18 on: May 16, 2011, 06:53:17 pm »
I think the whole scripting is in Ruby, so you can change the configuration and add mods.
Sig wipe!

Ashbad

  • Guest
Re: Ruby Discussion and Help
« Reply #19 on: May 16, 2011, 06:54:08 pm »
makes sense -- it's a simple language to learn, but extremely hard to master :)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Ruby Discussion and Help
« Reply #20 on: May 17, 2011, 07:03:07 pm »
Ruby is used in RPG Maker XP and VX. To be honest, though, RM is supposed to be a tool for game creators who don't want to code any single line, so XP purpose was kinda defeated, but by using Ruby you had so much more freedom apparently, although many RPG Maker users had troubles learning it from what I remember.

Also in some versions of XP/VX, the Ruby editor built-in the software used japanese characters. :(

Ashbad

  • Guest
Re: Ruby Discussion and Help
« Reply #21 on: May 17, 2011, 07:37:16 pm »
I wouldn't be surprised it was hard for them to learn -- it's not a good language to start out with, it took me months to finally declare myself a Ruby Knight, since it's so different from things like C++, Java, BASIC, and the like -- but once you get your foot in the door, the Principle of Least Astonishment (Meaning that if you know the language well, you can decipher and write straightforward code with little trouble) kicks in.

I'm even less surprised they have Japanese characters in a Ruby scripting system -- if it came out before 1999, then it was during the era when 95% of Ruby coding took place in Japan :)

Though, it's cool to see that XP and VX used it :D

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Ruby Discussion and Help
« Reply #22 on: May 17, 2011, 07:51:26 pm »
Plus, most RPG Maker users are used to just clicking stuff to insert pre-made events in a pre-made engine. They were not used to code. X.x

Ashbad

  • Guest
Re: Ruby Discussion and Help
« Reply #23 on: May 17, 2011, 08:06:28 pm »
very true.  That's why it's called a 'Maker' ;D though then again, some like Game Maker have somewhat-decent coding abilities.

also, good question from cemetech:

Quote from: christop
Maybe I'm misunderstanding something here (since I don't use Ruby), but couldn't you do exactly the same thing with regular (non-lambda) functions? Or are lambda functions somehow different than regular functions in Ruby? I thought one of the points of lambda functions was the ability to pass a (lambda) function to a second function as an argument, wherein the second function calls the lambda function inside of it. I don't see any of that going on in your code, which would make using lambda functions pointless.

response:

Quote from: Ashbad
I did it purely for practice of point ^-^ since they can be easily misused, I'm practicing to make sure I have them down right.

Yeah, it's a bit more complex, but they're more useful for higher-level math concepts, and even better for managing code snippets.

EDIT: I only answered part of your question methinks  :o so I'll go over how lambda functions can be invaluable:

let's say you have this working piece of code:

Code: [Select]
def Exponent(number,root)
   return number**root.to_f;end

if you want to load a variable such as 'Peanut' with an expression like "2 ** 5" you would constantly have to do:

Code: [Select]
Peanut = Exponent(2,5)
which is actually no problem.  But calling to lambdas is a better Ruby approach.  the exact same working code:

Code: [Select]
Peanut = lambda{|number,root| number**root}

Peanut.call(2,5)

you see, with this method, Peanut is directly attached to the function -- lambda functions are considered actual values, not functions themselves.  This allows for a higher level of abstraction in code, and nesting lambdas can be extremely useful when solving for complex equations -- it's easier to read and keep track of.  Such as in my Quadratic solver (which looks difficult but really is just a simple example of what I'm talking about) -- the lambda function isn't really a function -- it's a value that is determined by calling 'arguments' (I use that loosely, I forgot the true word for it)

This is one way to achieve 'anonymous functions' in Ruby, but actually isn't the most powerful way.  Another way that provides even less hassle is by declaring a Proc Function:

Code: [Select]
def ProcExample(input, NUMBAR)
  return lambda {|input| input.chomp.flatten.reverse},
                            lambda {||NUMBAR.to_s.reverse};end

uno, dos = ProcExample

The only real difference between a normal lambda statement and a proc statement is actually usage -- lambdas are when you simply just bind a function to a value.  Procs are when you use them on the fly to return a value based on 'arguments' (again, loosely used) like lambdas, but the difference is that they are usually more block-like and aren't directly bound to an actual variable -- very often seen as arguments of other lambdas or procs or even normal functions, or as returned values (with a lambda, you would return the value by using a call statement, procs would simply be declared at the moment).

I hope that clears a few things up :P

Ashbad

  • Guest
Re: Ruby Discussion and Help
« Reply #24 on: June 15, 2011, 10:26:41 pm »
For those interested, this is an awesome compilation of tricks used by advanced Ruby programmers, half I knew, the other half I didn't.  Its very useful: http://www.rubyinside.com/21-ruby-tricks-902.html

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Ruby Discussion and Help
« Reply #25 on: June 16, 2011, 12:49:53 am »
Cool, hopefully this is useful to some people here.

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Ruby Discussion and Help
« Reply #26 on: June 16, 2011, 08:29:26 am »
Ruby? Doesnt make sense to me, sorry.
I'm not a nerd but I pretend:

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: Ruby Discussion and Help
« Reply #27 on: July 02, 2011, 12:32:40 pm »
Oh, tryruby.org is FAULTY. I tried every single example EXACTLY the same way it was shown in the tutorials, and EVERY TIME I got this:

SyntaxError: <main>:69: syntax error, unexpected $undefined

It showed to enter 4 * 10, and I did. EVERY EXAMPLE shown threw that error when I tried using them in the tryruby built in prompt.

Oh and slightly off topic: EnvisionDev now includes Ruby support.

Ashbad

  • Guest
Re: Ruby Discussion and Help
« Reply #28 on: July 02, 2011, 12:36:48 pm »
hmm, interesting, I just tried again and it worked.  Perhaps for some reason your browser wasn't compatible with the console?

From what the error was it sounds like it ran into a weird symbol somewhere, which means that it most likely wasn't using ANY of the standard resources.  It should be fine in an actual Ruby script, though.

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: Ruby Discussion and Help
« Reply #29 on: July 02, 2011, 12:38:29 pm »
I'll try it in a real Ruby interpreter.