Class: Origami::Boolean
- Inherits:
-
Object
- Object
- Origami::Boolean
- Includes:
- Object
- Defined in:
- lib/origami/boolean.rb,
lib/origami/obfuscation.rb
Overview
Class representing a Boolean Object. A Boolean Object can be true or false.
Constant Summary collapse
- TOKENS =
:nodoc:
%w[true false]
- @@regexp =
Regexp.new(WHITESPACES + "(?<value>#{Regexp.union(TOKENS)})")
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Converts self into a Ruby boolean, that is TrueClass or FalseClass instance.
Attributes included from Object
#file_offset, #generation, #no, #objstm_offset, #parent
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #false? ⇒ Boolean
-
#initialize(value) ⇒ Boolean
constructor
Creates a new Boolean value.
-
#to_s(eol: $/) ⇒ Object
(also: #to_obfuscated_str)
:nodoc:.
- #true? ⇒ Boolean
Methods included from Object
#cast_to, #copy, #document, #export, included, #indirect?, #indirect_parent, #logicalize, #logicalize!, #native_type, #numbered?, #post_build, #pre_build, #reference, #set_document, #set_indirect, skip_until_next_obj, #solve, #to_o, #type, typeof, #version_required, #xrefs
Constructor Details
#initialize(value) ⇒ Boolean
Creates a new Boolean value.
- value
-
true or false.
39 40 41 42 43 44 45 46 47 |
# File 'lib/origami/boolean.rb', line 39 def initialize(value) unless value.is_a?(TrueClass) || value.is_a?(FalseClass) raise TypeError, "Expected type TrueClass or FalseClass, received #{value.class}." end super() @value = (value == true) end |
Instance Attribute Details
#value ⇒ Object (readonly)
Converts self into a Ruby boolean, that is TrueClass or FalseClass instance.
72 73 74 |
# File 'lib/origami/boolean.rb', line 72 def value @value end |
Class Method Details
.parse(stream, _parser = nil) ⇒ Object
:nodoc:
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/origami/boolean.rb', line 53 def self.parse(stream, _parser = nil) # :nodoc: scanner = Parser.init_scanner(stream) offset = scanner.pos if scanner.scan(@@regexp).nil? raise InvalidBooleanObjectError end value = (scanner['value'] == "true") bool = Boolean.new(value) bool.file_offset = offset bool end |
Instance Method Details
#==(other) ⇒ Object
82 83 84 |
# File 'lib/origami/boolean.rb', line 82 def ==(other) @value == other end |
#to_s(eol: $/) ⇒ Object Also known as: to_obfuscated_str
:nodoc:
49 50 51 |
# File 'lib/origami/boolean.rb', line 49 def to_s(eol: $/) # :nodoc: super(@value.to_s, eol: eol) end |