Class: MinitestToRspec::Input::Model::HashExp

Inherits:
Base
  • Object
show all
Defined in:
lib/minitest_to_rspec/input/model/hash_exp.rb

Overview

Data object. Represents a ‘:hash` S-expression.

Instance Method Summary collapse

Methods included from SexpAssertions

#assert_sexp_type, #assert_sexp_type_array, #sexp_type?

Constructor Details

#initialize(sexp) ⇒ HashExp

Returns a new instance of HashExp.



10
11
12
13
# File 'lib/minitest_to_rspec/input/model/hash_exp.rb', line 10

def initialize(sexp)
  assert_sexp_type(:hash, sexp)
  @exp = sexp.dup
end

Instance Method Details

#to_hObject

A slightly nicer implementation would be: ‘@exp.each_slice(2).to_h` but that would require ruby >= 2.1



18
19
20
# File 'lib/minitest_to_rspec/input/model/hash_exp.rb', line 18

def to_h
  Hash[@exp[1..-1].each_slice(2).to_a]
end