Skip to content

Instantly share code, notes, and snippets.

@chad
Created April 7, 2011 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chad/908227 to your computer and use it in GitHub Desktop.
Save chad/908227 to your computer and use it in GitHub Desktop.
def create_multipler(factor)
->param{param * factor}
end
times_2 = create_multipler(2)
p times_2.(4)
exit
class Foo
1_000_000_000.times do |n|
define_method("times_#{n}") do |param|
param * factor
end
end
end
Foo.new.times_873874
class MyClass
def self.create_multipler(factor)
define_method("times_#{factor}") do |param|
param * factor
end
end
end
MyClass.create_multipler(2)
m = MyClass.new
puts m.times_2(3) #=> 6
puts m.times_2(4) #=> 8
MyClass.create_multipler(3)
puts m.times_3("Ho! ") #=> Ho! Ho! Ho!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment