From e20dc472d3bc71ba927d6ddb0fb0032e1646df77 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Sun, 7 Jun 2015 22:41:52 +0200 Subject: [PATCH] Define implicit conversion for to_hash --- .../commands/define_implicit_conversions.rb | 4 ++++ spec/implicit_conversions_spec.rb | 3 +++ 2 files changed, 7 insertions(+) diff --git a/lib/naught/null_class_builder/commands/define_implicit_conversions.rb b/lib/naught/null_class_builder/commands/define_implicit_conversions.rb index c26a107..bc0bafb 100644 --- a/lib/naught/null_class_builder/commands/define_implicit_conversions.rb +++ b/lib/naught/null_class_builder/commands/define_implicit_conversions.rb @@ -11,6 +11,10 @@ def to_ary [] end + def to_hash + {} + end + def to_str '' end diff --git a/spec/implicit_conversions_spec.rb b/spec/implicit_conversions_spec.rb index 95b4eed..43e5b68 100644 --- a/spec/implicit_conversions_spec.rb +++ b/spec/implicit_conversions_spec.rb @@ -16,6 +16,9 @@ it 'implicitly converts to an empty array' do expect(null.to_ary).to eq([]) end + it 'implicitly converts to an empty hash' do + expect(null.to_hash).to eq({}) + end it 'implicitly converts to an empty string' do expect(null.to_str).to eq('') end