Class: Fable::FloatValue

Inherits:
Value show all
Defined in:
lib/fable/value.rb

Instance Attribute Summary

Attributes inherited from Value

#value_object

Attributes inherited from RuntimeObject

#original_object, #own_debug_metadata, #parent, #path

Instance Method Summary collapse

Methods inherited from Value

#bad_cast_exception, #copy, create

Methods inherited from RuntimeObject

#compact_path_string, #convert_path_to_relative, #copy, #debug_line_number_of_path, #debug_metadata, #indentation_string, #resolve_path, #root_content_container

Constructor Details

#initialize(value = 0.0) ⇒ FloatValue

Returns a new instance of FloatValue.



97
98
99
# File 'lib/fable/value.rb', line 97

def initialize(value = 0.0)
  super(value)
end

Instance Method Details

#cast(new_type) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/fable/value.rb', line 101

def cast(new_type)
  if new_type == self.class
    return self
  end

  if new_type == IntValue
    return IntValue.new(self.value.to_i)
  end

  if new_type == StringValue
    return StringValue.new(self.value.to_s)
  end

  raise bad_cast_exception(new_type)
end

#to_sObject



117
118
119
120
121
122
123
# File 'lib/fable/value.rb', line 117

def to_s
  if value % 1 == 0
    value.to_i.to_s
  else
    value.round(7).to_s
  end
end

#truthy?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/fable/value.rb', line 93

def truthy?
  return value != 0.0
end

#value_typeObject



89
90
91
# File 'lib/fable/value.rb', line 89

def value_type
  return FloatValue
end