-
-
Save vasilakisfil/0f1cffd45fa651e1f3e5c5a697c15d81 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
class Foo | |
class << self | |
def method_missing(meth, *args) | |
if new.respond_to? meth | |
new.send(meth, *args) | |
else | |
super | |
end | |
end | |
def respond_to_missing?(meth, _) | |
new.respond_to?(meth) || super | |
end | |
end | |
def foo(a: "default A", b: "default B") | |
puts "a: #{a}, b: #{b}" | |
end | |
def call_foo(*args) | |
foo(*args) | |
end | |
def elements(elements) | |
elements.each{|el| | |
puts el | |
} | |
end | |
def elements2(elements, key:) | |
elements.each{|el| | |
puts el | |
} | |
puts key | |
end | |
end | |
Foo.call_foo(a: "it's an a!", b: "it's a B") | |
Foo.call_foo({a: "it's an a!", b: "it's a B"}) | |
Foo.call_foo | |
Foo.elements([1, 2]) | |
Foo.elements2([1, 2], key: "A key") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment