Skip to content

Instantly share code, notes, and snippets.

@vasilakisfil
Last active March 4, 2021 14:53
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 vasilakisfil/0f1cffd45fa651e1f3e5c5a697c15d81 to your computer and use it in GitHub Desktop.
Save vasilakisfil/0f1cffd45fa651e1f3e5c5a697c15d81 to your computer and use it in GitHub Desktop.
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