Class: JSONBuilder::Value
- Inherits:
-
Object
- Object
- JSONBuilder::Value
- Defined in:
- lib/json_builder/value.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(scope, arg, &block) ⇒ Value
constructor
Public: Creates.
-
#to_s ⇒ Object
Public: Determines of the stored value has a special return value or calls the default to_s on it.
Constructor Details
#initialize(scope, arg, &block) ⇒ Value
Public: Creates
scope - The view scope context for any variables. arg - Could be string, hash, or any other Ruby value. block - Yielding any block passed to the element.
Returns an instance of JSONBuilder::Member, JSONBuilder::Compiler or String.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/json_builder/value.rb', line 15 def initialize(scope, arg, &block) if block_given? @value = Compiler.new(:scope => scope) compiled = @value.compile(arg, &block) # For the use case that the passed in block returns a non-member object # or normal Ruby object @value = compiled unless compiled.is_a?(Member) else @value = arg end end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/json_builder/value.rb', line 5 def value @value end |
Instance Method Details
#to_s ⇒ Object
Public: Determines of the stored value has a special return value or calls the default to_s on it.
Returns a String.
32 33 34 |
# File 'lib/json_builder/value.rb', line 32 def to_s @value.respond_to?(:to_builder) ? @value.to_builder : @value.to_s end |