Class: RFC8259::Value Abstract
- Inherits:
-
Object
- Object
- RFC8259::Value
- Defined in:
- lib/RFC8259/value.rb
Overview
This class is abstract.
The Values, as described in RFC8259 section 3.
value = false / null / true / object / array / number / string
Class Method Summary collapse
-
.from_ast(ast) ⇒ Value
Parse the AST from parser, and convert into corrsponding values.
Instance Method Summary collapse
-
#inspect ⇒ ::String
The class in string.
-
#plain_old_ruby_object ⇒ Object
convert to Ruby's value.
-
#pretty_print(pp) ⇒ Object
For pretty print (require 'pp' beforehand).
Class Method Details
.from_ast(ast) ⇒ Value
Note:
the input MUST be a tree. No cyclic lists, nor even direct-acycric graphs are allowed by definition. Such input can cause undefined behaviour.
Parse the AST from parser, and convert into corrsponding values.
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/RFC8259/value.rb', line 48 def self.from_ast ast klass = case ast.first when :false then RFC8259::False when :null then RFC8259::Null when :true then RFC8259::True when :object then RFC8259::Object when :array then RFC8259::Array when :number then RFC8259::Number when :string then RFC8259::String end return klass.from_ast ast end |
Instance Method Details
#inspect ⇒ ::String
Returns the class in string.
67 68 69 |
# File 'lib/RFC8259/value.rb', line 67 def inspect sprintf "#<%p>", self.class end |
#plain_old_ruby_object ⇒ Object
convert to Ruby's value
62 63 64 |
# File 'lib/RFC8259/value.rb', line 62 def plain_old_ruby_object raise RuntimeError, 'abstruct method called' end |
#pretty_print(pp) ⇒ Object
For pretty print (require 'pp' beforehand)
73 74 75 |
# File 'lib/RFC8259/value.rb', line 73 def pretty_print pp pp.object_group self do end # nothing end |