Skip to content

Instantly share code, notes, and snippets.

@kotay

kotay/Listhp.rb Secret

Created September 14, 2012 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kotay/2a0de4273719f1a429ea to your computer and use it in GitHub Desktop.
Save kotay/2a0de4273719f1a429ea to your computer and use it in GitHub Desktop.
Trying to write a haskel
class AnLisp
def self.method_missing(name, *args, &b)
if name =~ /(.*)=$/
define_method(name.to_s.gsub('=', ''), *args, &b)
else
super if defined? super
end
end
end
Jimmy = Class.new(AnLisp) do
self.name = ->(a) { puts "I am #{a}" }
end
Jimmy.new.name("Jim")
# Don't suppose you know of a way to avoid the need for the "self." in self.name?
# Can one define another #method_missing on Jimmy instances?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment