Class: ID3::RestrictedOrderedHash
Overview
Class RestrictedOrderedHash
Direct Known Subclasses
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
-
#locked ⇒ Object
Returns the value of attribute locked.
-
#order ⇒ Object
Returns the value of attribute order.
Instance Method Summary collapse
- #[]=(key, val) ⇒ Object
- #delete(key) ⇒ Object
-
#initialize ⇒ RestrictedOrderedHash
constructor
A new instance of RestrictedOrderedHash.
-
#inspect ⇒ Object
returns the human-readable ordered hash in correct order ..
- #lock ⇒ Object
-
#old_delete ⇒ Object
users can not delete entries from a locked hash..
- #old_store ⇒ Object
- #values ⇒ Object
Methods inherited from Hash
#inverse, #invert, #old_invert
Constructor Details
#initialize ⇒ RestrictedOrderedHash
Returns a new instance of RestrictedOrderedHash.
676 677 678 679 680 681 |
# File 'lib/id3.rb', line 676 def initialize @locked = false @count = 0 @order = [] super end |
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
670 671 672 |
# File 'lib/id3.rb', line 670 def count @count end |
#locked ⇒ Object
Returns the value of attribute locked.
670 671 672 |
# File 'lib/id3.rb', line 670 def locked @locked end |
#order ⇒ Object
Returns the value of attribute order.
670 671 672 |
# File 'lib/id3.rb', line 670 def order @order end |
Instance Method Details
#[]=(key, val) ⇒ Object
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 |
# File 'lib/id3.rb', line 685 def []= (key,val) if self[key] self.old_store(key,val) else if @locked # we're not allowed to add new keys! raise ArgumentError, "You can not add new keys! The ID3-frame #{@name} has fixed entries!\n" + " valid key are: " + self.keys.join(",") +"\n" else @count += 1 @order += [key] self.old_store(key,val) end end end |
#delete(key) ⇒ Object
729 730 731 732 733 734 |
# File 'lib/id3.rb', line 729 def delete (key) if !@locked old_delete(key) @order.delete(key) end end |
#inspect ⇒ Object
returns the human-readable ordered hash in correct order .. ;-)
712 713 714 715 716 717 718 719 720 721 722 723 |
# File 'lib/id3.rb', line 712 def inspect first = true str = "{" self.order.each{ |key| str += ", " if !first str += key.inspect str += "=>" str += (self[key]).inspect first = false } str +="}" end |
#lock ⇒ Object
672 673 674 |
# File 'lib/id3.rb', line 672 def lock @locked = true end |
#old_delete ⇒ Object
users can not delete entries from a locked hash..
727 |
# File 'lib/id3.rb', line 727 alias old_delete delete |
#old_store ⇒ Object
683 |
# File 'lib/id3.rb', line 683 alias old_store []= |
#values ⇒ Object
702 703 704 705 706 707 708 |
# File 'lib/id3.rb', line 702 def values array = [] @order.each { |key| array.push self[key] } array end |