Files
news.gitea.happylizard.me/bin/gems/hashery-2.1.2/demo/08_propery_hash.rdoc
T
pizza2d1 4cee170d66
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 9s
Add bin and edit workflow
2026-09-16 13:11:16 -06:00

35 lines
715 B
Plaintext

= PropertyHash
The Property hash can be used an object in itself.
h = PropertyHash.new(:a=>1, :b=>2)
h[:a] #=> 1
h[:a] = 3
h[:a] #=> 3
Becuase the properties are fixed, if we try to set a key that is not present,
then we will get an error.
expect ArgumentError do
h[:x] = 5
end
The PropertyHash can also be used as a superclass.
class MyPropertyHash < PropertyHash
property :a, :default => 1
property :b, :default => 2
end
h = MyPropertyHash.new
h[:a] #=> 1
h[:a] = 3
h[:a] #=> 3
Again, if we try to set key that was not fixed, then we will get an error.
expect ArgumentError do
h[:x] = 5
end