Created
October 30, 2012 09:37
-
-
Save richo/3979268 to your computer and use it in GitHub Desktop.
This file contains 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
self.class.send(:define_method, :"has space") do |arg| | |
puts "lol" << arg | |
end | |
self.class.send(:define_method, :"has several spaces") do |arg| | |
puts "Ahahah. Lol." << arg | |
end | |
self.class.send(:define_method, :"takes several args") do |arg, arg2| | |
puts "tuuuuup" << arg << arg2 | |
end | |
self.instance_exec do | |
def method_missing(sym, *args) | |
# Splat args if passed in from a parent call | |
if args.length == 1 && args[0].is_a?(Array) && args[0][0].class == NameError | |
args = args[0] | |
end | |
method_names, arguments = args.partition { |a| a.class == NameError } | |
method([sym.to_s, *method_names.map(&:name)].join(" ")).call(*arguments) | |
rescue NameError => e | |
return [e, *arguments] | |
end | |
end | |
has space "rawr" | |
has several spaces "seriously" | |
takes several args "like", "this" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment