Skip to content

Instantly share code, notes, and snippets.

@rf-
Created December 15, 2012 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rf-/4292154 to your computer and use it in GitHub Desktop.
Save rf-/4292154 to your computer and use it in GitHub Desktop.
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
@krainboltgreene
Copy link

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.

@ConradIrwin
Copy link

@krainboltgreene luckily you don't need the . in this case https://gist.github.com/4292203

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment