-
-
Save kotay/2a0de4273719f1a429ea to your computer and use it in GitHub Desktop.
Trying to write a haskel
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
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