Class: Minjs::ECMA262::Boolean
- Defined in:
- lib/minjs/ecma262/literal.rb
Overview
Class of ECMA262 Boolean element
Constant Summary collapse
- @@true =
self.new(:true)
- @@false =
self.new(:false)
Instance Attribute Summary collapse
-
#val ⇒ Object
readonly
Returns the value of attribute val.
Attributes inherited from Base
Class Method Summary collapse
-
.get(val) ⇒ Object
get instance.
Instance Method Summary collapse
-
#==(obj) ⇒ Object
compare object.
-
#deep_dup ⇒ Object
duplicate object.
-
#ecma262_typeof ⇒ Symbol
return results of ‘typeof’ operator.
-
#initialize(val) ⇒ Boolean
constructor
A new instance of Boolean.
-
#left_hand_side_exp? ⇒ Boolean
True if expression is kind of LeftHandSideExpression.
-
#to_ecma262_boolean ⇒ Boolean
Returns results of ToBoolean().
-
#to_ecma262_number ⇒ Numeric
Returns results of ToNumber().
-
#to_ecma262_string ⇒ Numeric
Returns results of ToString().
-
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
-
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
- #true? ⇒ Boolean
Methods inherited from Literal
#lt?, #priority, #side_effect?, #ws?
Methods inherited from Base
#add_remove_paren, #concat, #replace
Constructor Details
#initialize(val) ⇒ Boolean
Returns a new instance of Boolean.
278 279 280 281 282 283 284 |
# File 'lib/minjs/ecma262/literal.rb', line 278 def initialize(val) if val.to_s == "true" @val = :"true" else @val = :"false" end end |
Instance Attribute Details
#val ⇒ Object (readonly)
Returns the value of attribute val.
276 277 278 |
# File 'lib/minjs/ecma262/literal.rb', line 276 def val @val end |
Class Method Details
.get(val) ⇒ Object
get instance
379 380 381 382 383 384 385 |
# File 'lib/minjs/ecma262/literal.rb', line 379 def self.get(val) if val.to_sym == :true || val == true @@true else @@false end end |
Instance Method Details
#==(obj) ⇒ Object
compare object
300 301 302 303 |
# File 'lib/minjs/ecma262/literal.rb', line 300 def ==(obj) self.class == obj.class and @val == obj.val end |
#deep_dup ⇒ Object
duplicate object
288 289 290 |
# File 'lib/minjs/ecma262/literal.rb', line 288 def deep_dup self #//not dup end |
#ecma262_typeof ⇒ Symbol
return results of ‘typeof’ operator.
371 372 373 |
# File 'lib/minjs/ecma262/literal.rb', line 371 def ecma262_typeof :boolean end |
#left_hand_side_exp? ⇒ Boolean
Returns true if expression is kind of LeftHandSideExpression.
312 313 314 |
# File 'lib/minjs/ecma262/literal.rb', line 312 def left_hand_side_exp? true end |
#to_ecma262_boolean ⇒ Boolean
Returns results of ToBoolean()
Returns true or false if trivial, otherwise nil.
344 345 346 347 348 349 350 |
# File 'lib/minjs/ecma262/literal.rb', line 344 def to_ecma262_boolean if @val == :false false else true end end |
#to_ecma262_number ⇒ Numeric
Returns results of ToNumber()
Returns number if value is trivial, otherwise nil.
360 361 362 363 364 365 366 |
# File 'lib/minjs/ecma262/literal.rb', line 360 def to_ecma262_number if @val == :false 0 else 1 end end |
#to_ecma262_string ⇒ Numeric
Returns results of ToString()
Returns string if value is trivial, otherwise nil.
328 329 330 331 332 333 334 |
# File 'lib/minjs/ecma262/literal.rb', line 328 def to_ecma262_string if @val == :false "false" else "true" end end |
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
307 308 309 |
# File 'lib/minjs/ecma262/literal.rb', line 307 def to_js( = {}) @val.to_s end |
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
295 296 297 |
# File 'lib/minjs/ecma262/literal.rb', line 295 def traverse(parent, &block) yield parent, self end |
#true? ⇒ Boolean
316 317 318 |
# File 'lib/minjs/ecma262/literal.rb', line 316 def true? @val == :true end |