Class: RememberTheMilkHash
- Inherits:
-
Hash
- Object
- Hash
- RememberTheMilkHash
- Defined in:
- lib/rtmapi.rb
Overview
a standard hash with some helper methods
Direct Known Subclasses
Constant Summary collapse
- @@strict_keys =
true
Instance Attribute Summary collapse
-
#rtm ⇒ Object
Returns the value of attribute rtm.
Class Method Summary collapse
Instance Method Summary collapse
-
#arrayify_value(key) ⇒ Object
guarantees that a given key corresponds to an array, even if it’s an empty array.
- #id ⇒ Object
-
#initialize(rtm_object = nil) ⇒ RememberTheMilkHash
constructor
A new instance of RememberTheMilkHash.
- #method_missing(key, *args) ⇒ Object
- #rtm_id ⇒ Object
Constructor Details
#initialize(rtm_object = nil) ⇒ RememberTheMilkHash
Returns a new instance of RememberTheMilkHash.
442 443 444 445 |
# File 'lib/rtmapi.rb', line 442 def initialize(rtm_object = nil) super @rtm = rtm_object end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key, *args) ⇒ Object
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
# File 'lib/rtmapi.rb', line 467 def method_missing( key, *args ) name = key.to_s setter = false if name[-1,1] == '=' name = name.chop setter = true end if name == "" name = "rtm_nil".to_sym else name = name.to_sym end # TODO: should we allow the blind setting of values? (i.e., only do this test # if setter==false ) raise "unknown hash key<#{name}> requested for #{self.inspect}" if @@strict_keys && !self.has_key?(name) if setter self[name] = *args else self[name] end end |
Instance Attribute Details
#rtm ⇒ Object
Returns the value of attribute rtm.
435 436 437 |
# File 'lib/rtmapi.rb', line 435 def rtm @rtm end |
Class Method Details
.strict_keys=(value) ⇒ Object
438 439 440 |
# File 'lib/rtmapi.rb', line 438 def self.strict_keys=( value ) @@strict_keys = value end |
Instance Method Details
#arrayify_value(key) ⇒ Object
guarantees that a given key corresponds to an array, even if it’s an empty array
456 457 458 459 460 461 462 463 464 |
# File 'lib/rtmapi.rb', line 456 def arrayify_value( key ) if !self.has_key?(key) self[key] = [] elsif self[key].class != Array self[key] = [ self[key] ].compact else self[key] end end |
#id ⇒ Object
447 448 449 |
# File 'lib/rtmapi.rb', line 447 def id rtm_id || object_id end |
#rtm_id ⇒ Object
451 452 453 |
# File 'lib/rtmapi.rb', line 451 def rtm_id self[:id] end |