Javascript like Ruby
After reading Yehuda Katz’s post Metaprogramming in Ruby: It’s All About the Self and I’ve realized you can do some funky javascript like stuff in ruby.
For Example you can define methods that have access to a javascript kind of “private” variable:
You could use this technique to simulate module variables like so:
You can even apply a method onto another object just like Javascript’s Function#apply
The difference being in Ruby you can only bind (and therefore call) a method on an instance of the object it was defined on. For instance if you try and bind Hash#keys onto an array instance you’ll get the `TypeError: bind argument must be an instance of Hash`
1 note
POSTED Monday November 16th
-
deadlyicon liked this
-
jaredgrippe posted this