Class: Fable::ListValue
- Inherits:
-
Value
- Object
- RuntimeObject
- Value
- Fable::ListValue
- Defined in:
- lib/fable/value.rb
Instance Attribute Summary
Attributes inherited from Value
Attributes inherited from RuntimeObject
#original_object, #own_debug_metadata, #parent, #path
Class Method Summary collapse
Instance Method Summary collapse
- #cast(new_type) ⇒ Object
-
#initialize(single_item = nil, single_value = nil) ⇒ ListValue
constructor
A new instance of ListValue.
- #truthy? ⇒ Boolean
- #value_type ⇒ Object
Methods inherited from Value
#bad_cast_exception, #copy, create, #to_s
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(single_item = nil, single_value = nil) ⇒ ListValue
Returns a new instance of ListValue.
305 306 307 308 309 310 311 312 313 |
# File 'lib/fable/value.rb', line 305 def initialize(single_item=nil, single_value=nil) if single_item.nil? && single_value.nil? super(InkList.new) elsif single_item.is_a?(InkList) super(InkList.copy_list(single_item)) else super(InkList.new_with_single_item(single_item, single_value)) end end |
Class Method Details
.retain_list_origins_for_assignment(old_value, new_value) ⇒ Object
315 316 317 318 319 320 |
# File 'lib/fable/value.rb', line 315 def self.retain_list_origins_for_assignment(old_value, new_value) # When assigning the empty list, try to retain any initial origin names if (old_value.is_a?(ListValue) && new_value.is_a?(ListValue) && new_value.value.list.size == 0) new_value.value.set_initial_origin_names(old_value.value.origin_names) end end |
Instance Method Details
#cast(new_type) ⇒ Object
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/fable/value.rb', line 270 def cast(new_type) if new_type == IntValue max = value.max_item if max.nil? return IntValue.new(0) else return IntValue.new(max) end end if new_type == FloatValue max = value.max_item if max.nil? return FloatValue.new(0.0) else return FloatValue.new(max) end end if new_type == StringValue max = value.max_item if max.nil? return StringValue.new("") else return StringValue.new(max) end end if new_type == self.class return self end raise bad_cast_exception(new_type) end |
#truthy? ⇒ Boolean
266 267 268 |
# File 'lib/fable/value.rb', line 266 def truthy? return value.count > 0 end |
#value_type ⇒ Object
262 263 264 |
# File 'lib/fable/value.rb', line 262 def value_type return OrderedValueTypes[ListValue] end |