Skip to content

Instantly share code, notes, and snippets.

@noelrappin
Created December 30, 2022 17:59
Show Gist options
  • Save noelrappin/6d47b777686c35f3f89107cd6eb7c68f to your computer and use it in GitHub Desktop.
Save noelrappin/6d47b777686c35f3f89107cd6eb7c68f to your computer and use it in GitHub Desktop.
splat_test.rb
class Consumer
def takes_args(a, b, c)
p "#{a} #{b} #{c}"
end
def takes_keys(a:, b:, c:)
p "#{a} #{b} #{c}"
end
end
class NotAnArrayOrAHash
def initialize(a, b, c)
@a = a
@b = b
@c = c
end
def to_a
[@a, @b, @c]
end
def to_hash
{a: @a, b: @b, c: @c}
end
end
obj = NotAnArrayOrAHash.new(1, 2, 3)
c = Consumer.new
c.takes_args(*obj)
c.takes_keys(**obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment