diff --git a/src/data.rb b/src/data.rb index 36de0eff0..cbafe2b54 100644 --- a/src/data.rb +++ b/src/data.rb @@ -34,6 +34,11 @@ def self.define(*members, &block) end end + define_method(:inspect) do + "#" + end + alias_method :to_s, :inspect + define_method(:to_h) { members.to_h { |member| [member, public_send(member)] } } define_method(:with) do |**kwargs| diff --git a/test/natalie/data_test.rb b/test/natalie/data_test.rb index 598184d74..737b1b94e 100644 --- a/test/natalie/data_test.rb +++ b/test/natalie/data_test.rb @@ -6,6 +6,14 @@ it 'transforms the data object into a hash' do 1.should == 1 end + + it 'results in a readable representation' do + 1.should == 1 + end + + it 'results in a readable representation' do + 1.should == 1 + end end end @@ -16,4 +24,18 @@ data.to_h.should == { amount: 42, unit: 'km' } end end + + describe 'Data#inspect' do + it 'results in a readable representation' do + data = DataSpecs::Measure.new(amount: 42, unit: 'km') + data.inspect.should == '#' + end + end + + describe 'Data#to_s' do + it 'results in a readable representation' do + data = DataSpecs::Measure.new(amount: 42, unit: 'km') + data.to_s.should == '#' + end + end end