Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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
You can’t perform that action at this time.