Created
December 15, 2012 08:34
-
-
Save rf-/4292154 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.method_missing(name, *args) | |
name | |
end | |
def function(*param_names, &block) | |
klass = Class.new { attr_accessor :this, *param_names } | |
this = TOPLEVEL_BINDING.eval('self') | |
proc do |*params| | |
context = klass.new | |
context.this = this | |
param_names.each do |param_name| | |
context.send "#{param_name}=", params.shift | |
end | |
context.instance_eval &block | |
end | |
end | |
fn = function(foo, bar) { foo + bar * 10; } | |
fn.(1, 2) # => 21 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This
.()
syntax has got to be the worst new practice I've seen since getting into Ruby. Whomever pointed this out: Thanks for adding another confusing piece of syntax to explain to new people.