Re:Confessions of a Ruby Developer Whose Heart was Stolen by...
by csense on Thursday June 13, 2013 @06:30PM
(#5877017)
This is really interesting. I guess some of my examples were relying on using a similar lexer as C -- which you probably couldn't in Ruby. I'll have to think some more about what a Ruby lexer would look like...
But again, it steepens the learning curve -- it's so different from other languages that it's actually kind of hard to immediately see all the implications of "well Ruby's lexer is different than C's lexer".
For the code samples going forward, keep in mind that in ruby you don't need a literal return statement to return a value from a method. Just whatever value is last, is returned:
That method would always return 5.> But then if the b() call itself returns a function, then is that function auto-called as well?
No, the only way to pass a method is by using method(method_name_here), which returns a Method object. To execute a Method object, you need to call call on it:
So if you have a method that returns a method, it should not be automatically called, so there's no loop necessary: Then z is a Method object, namely a.Some experiments to answer your questions (I admit I wasn't sure for all of them what the outcome would be). IRB is Ruby's repl: