Sha256: f9f006eaf8bc3c68ccdf9aad5ac885042f36fac0b95924c6875bd5f498dcc994
Contents?: true
Size: 599 Bytes
Versions: 3
Compression:
Stored size: 599 Bytes
Contents
require 'rspec' require 'abstractivator/value_map' describe '#value_map' do Foo = Struct.new(:a) it 'maps enumerables' do expect([[:a, 1], [:b, 2]].value_map(&:reverse)).to eql [[1, :a], [2, :b]] expect({a: 1, b: 2}.value_map(&:reverse)).to eql [[1, :a], [2, :b]] end it 'maps single values' do expect(3.value_map(&method(:square))).to eql 9 end it 'structs are treated as single values' do expect(Foo.new(42).value_map { |x| x.a }).to eql 42 end it 'maps nil' do expect(nil.value_map(&method(:square))).to be nil end def square(x) x * x end end
Version data entries
3 entries across 3 versions & 1 rubygems