Skip to content

Instantly share code, notes, and snippets.

@robacarp
Created December 1, 2016 21:41
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 robacarp/11aed78575b7b78db1b718016497f6aa to your computer and use it in GitHub Desktop.
Save robacarp/11aed78575b7b78db1b718016497f6aa to your computer and use it in GitHub Desktop.
# require 'byebug'
puts "ruby -v is #{RUBY_VERSION} but should be '2.2.2'" unless RUBY_VERSION == '2.2.2'
class Hash
def symbolize_keys
dup = self.class.new
each_key do |key|
dup[ key.to_sym ] = self[key]
end
dup
# Other implementations tried:
# to_a.map{ |pair| pair[0] = pair[0].to_sym; pair }.to_h
end
end
class MagicDance
def initialize
@rolled_back = false
end
def dance(one:, two:, **splat)
puts "#{two} #{one}"
puts splat
end
def one
# ============================
# Buggy, but only when it's by itself in the method:
splat = { "three" => :anything }.symbolize_keys
GC.start # fixes it
dance two: :not, one: :broken, **splat
# ============================
# Uncomment to see above statement succeed
# dance two: :not, one: :broken, **{ three: :anything }
# ============================
# Uncomment to see above statement succeed
# dance two: :not, one: :broken, three: :anything
end
# Even in different methods!
# Uncomment to see above statement succeed
# def two
# dance two: :not, one: :broken, **{ three: :anything }
# end
end
MagicDance.new.one
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment