Class: RubyJsonParser::AST::KeyValuePairNode
- Defined in:
- lib/ruby_json_parser/ast.rb
Overview
Represents a key-value pair eg. ‘“foo”: 123`
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(key, value) ⇒ KeyValuePairNode
constructor
A new instance of KeyValuePairNode.
- #inspect(indent = 0) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(key, value) ⇒ KeyValuePairNode
Returns a new instance of KeyValuePairNode.
220 221 222 223 |
# File 'lib/ruby_json_parser/ast.rb', line 220 def initialize(key, value) @key = key @value = value end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
214 215 216 |
# File 'lib/ruby_json_parser/ast.rb', line 214 def key @key end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
217 218 219 |
# File 'lib/ruby_json_parser/ast.rb', line 217 def value @value end |
Instance Method Details
#==(other) ⇒ Object
226 227 228 229 230 |
# File 'lib/ruby_json_parser/ast.rb', line 226 def ==(other) return false unless other.is_a?(KeyValuePairNode) key == other.key && value == other.value end |
#inspect(indent = 0) ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/ruby_json_parser/ast.rb', line 240 def inspect(indent = 0) buff = String.new buff << "#{INDENT_UNIT * indent}(pair" k = key buff << "\n" buff << if k k.inspect(indent + 1) else "#{INDENT_UNIT * (indent + 1)}<nil>" end v = value buff << "\n" buff << if v v.inspect(indent + 1) else "#{INDENT_UNIT * (indent + 1)}<nil>" end buff << ')' buff end |
#to_s ⇒ Object
233 234 235 236 237 |
# File 'lib/ruby_json_parser/ast.rb', line 233 def to_s return value.to_s unless key "#{key}: #{value}" end |