and the examples themselves just look a little crazy, imo. Not crazy because of what you are trying to do, but in how you are trying to do it. What was the intent of calling a method that defines an argument without an argument? That's not a problem of the language; that's just an error in coding. There are all kinds of things in Ruby to handle method definition. Arguments can have defaults. You can use splat and unsplat to handle unspecified arguments and composing arguments of various # on the fly. You can pass in blocks specifically (&something) or optionally (yield, etc.). Procs allow argument sillyness and returning the parent method by explicit return in the proc body, lambdas don't, etc. Ruby is a great language, and you should give it a college try for several months to get the hang of it.
By the same token, I have no clue what you are trying to do here:
def f(x); def g(y); x + y; end; g(2); end; f(2)
# undefined local variable or method `x'
You can define methods on object instances, if that is what you are getting at (define_method/class_eval/etc.), and getting familiar with blocks, procs/lambdas might help. It isn't JavaScript, but I can't think of that much that I couldn't do in Ruby (barring high performance, compile-time type checking, etc.)
I appreciate the examples may not be working for you. We'll try to improve them.
However: Some of our programming environment's server infrastructure is built in Ruby (mainly because it has great git support, and we commit all edits to repos). One of Pyret's lead developers spent over a year on a widely-used RoR system. We've given it far more than the old collegiate try. Some of us have lived in it.
If you're happy with Ruby, great! We're not trying to convert you. But there are people who would find the Ruby code we've written "natural" and the resulting behavior thus unnatural.
method_as_fun = o.my-method
which should be:
method_as_fun = o.my_method
and the examples themselves just look a little crazy, imo. Not crazy because of what you are trying to do, but in how you are trying to do it. What was the intent of calling a method that defines an argument without an argument? That's not a problem of the language; that's just an error in coding. There are all kinds of things in Ruby to handle method definition. Arguments can have defaults. You can use splat and unsplat to handle unspecified arguments and composing arguments of various # on the fly. You can pass in blocks specifically (&something) or optionally (yield, etc.). Procs allow argument sillyness and returning the parent method by explicit return in the proc body, lambdas don't, etc. Ruby is a great language, and you should give it a college try for several months to get the hang of it.
By the same token, I have no clue what you are trying to do here:
def f(x); def g(y); x + y; end; g(2); end; f(2) # undefined local variable or method `x'
You can define methods on object instances, if that is what you are getting at (define_method/class_eval/etc.), and getting familiar with blocks, procs/lambdas might help. It isn't JavaScript, but I can't think of that much that I couldn't do in Ruby (barring high performance, compile-time type checking, etc.)