Module: Str2Hash::String

Defined in:
lib/str2hash.rb

Instance Method Summary collapse

Instance Method Details

#to_hHash

Converts the string to a hash representation

Examples:

"{ :foo => 'bar'}".to_h
=> {:foo=>"bar"}

Returns:

  • (Hash)

    Hash representation of the string

Raises:

  • (Parslet::ParseFailed)

    If parsing of the string fails



152
153
154
155
156
157
158
159
160
161
# File 'lib/str2hash.rb', line 152

def to_h

  p = HashParse.new
  t = HashTransform.new

  h_str = self.clone
  h_str.strip!
  t.apply(p.parse(self.strip))

end