Created
December 30, 2022 17:59
-
-
Save noelrappin/6d47b777686c35f3f89107cd6eb7c68f to your computer and use it in GitHub Desktop.
splat_test.rb
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 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