Skip to content

Instantly share code, notes, and snippets.

@molawson
Created March 30, 2022 20:05
Show Gist options
  • Save molawson/c8836bc18d38774fc0ed47db07e734d9 to your computer and use it in GitHub Desktop.
Save molawson/c8836bc18d38774fc0ed47db07e734d9 to your computer and use it in GitHub Desktop.
class DefinitelyNotHash
def initialize(val)
@val = val
end
end
class HashIsh
def initialize(val)
@val = val
end
def to_hash
{ value: @val }
end
end
class NotQuiteHash
def initialize(val)
@val = val
end
def to_h
{ value: @val }
end
end
def test(*args, **kwargs)
puts "ARGS: #{args.inspect}"
puts "KWARGS: #{kwargs.inspect}"
end
# pry
[1] pry(main)> require_relative 'test'
=> true
[2] pry(main)> test NotHash.new("asdf")
ARGS: [#<NotHash:0x0000000153c4e3f8 @val="asdf">]
KWARGS: {}
=> nil
[3] pry(main)> test NotQuiteHash.new("asdf")
ARGS: [#<NotQuiteHash:0x0000000153c24620 @val="asdf">]
KWARGS: {}
=> nil
[4] pry(main)> test HashIsh.new("asdf")
ARGS: []
KWARGS: {:value=>"asdf"}
=> nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment