Class: Stix2::Boolean

Inherits:
Object
  • Object
show all
Defined in:
lib/stix2/boolean.rb

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Boolean

Returns a new instance of Boolean.



3
4
5
6
7
8
9
10
11
12
# File 'lib/stix2/boolean.rb', line 3

def initialize(value)
  case value
  when String
    @value = !!(value =~ /\A(true|t|yes|y|1)\z/i)
  when Numeric
    @value = !value.to_i.zero?
  else
    @value = (value == true)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



14
15
16
# File 'lib/stix2/boolean.rb', line 14

def method_missing(m, *args, &block)
  @value.send(m, *args, &block)
end