Class: MinitestToRspec::Input::Model::HashExp
- Defined in:
- lib/minitest_to_rspec/input/model/hash_exp.rb
Overview
Data object. Represents a ‘:hash` S-expression.
Instance Method Summary collapse
-
#initialize(sexp) ⇒ HashExp
constructor
A new instance of HashExp.
-
#to_h ⇒ Object
A slightly nicer implementation would be: ‘@exp.each_slice(2).to_h` but that would require ruby >= 2.1.
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_h ⇒ Object
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 |