Class: OsVm::ShellCollection
- Inherits:
-
Object
- Object
- OsVm::ShellCollection
- Includes:
- Enumerable
- Defined in:
- lib/osvm/shell_collection.rb
Instance Attribute Summary collapse
-
#machine ⇒ Object
readonly
protected
Returns the value of attribute machine.
-
#shells ⇒ Object
readonly
protected
Returns the value of attribute shells.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #each ⇒ Object
- #fetch(name, *default) ⇒ Object
-
#initialize(machine, shells) ⇒ ShellCollection
constructor
A new instance of ShellCollection.
- #key?(name) ⇒ Boolean (also: #include?, #member?)
- #keys ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(machine, shells) ⇒ ShellCollection
Returns a new instance of ShellCollection.
5 6 7 8 |
# File 'lib/osvm/shell_collection.rb', line 5 def initialize(machine, shells) @machine = machine @shells = shells.transform_keys(&:to_s).freeze end |
Instance Attribute Details
#machine ⇒ Object (readonly, protected)
Returns the value of attribute machine.
46 47 48 |
# File 'lib/osvm/shell_collection.rb', line 46 def machine @machine end |
#shells ⇒ Object (readonly, protected)
Returns the value of attribute shells.
46 47 48 |
# File 'lib/osvm/shell_collection.rb', line 46 def shells @shells end |
Instance Method Details
#[](name) ⇒ Object
10 11 12 |
# File 'lib/osvm/shell_collection.rb', line 10 def [](name) fetch(name) end |
#each ⇒ Object
36 37 38 |
# File 'lib/osvm/shell_collection.rb', line 36 def each(&) shells.each(&) end |
#fetch(name, *default) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/osvm/shell_collection.rb', line 14 def fetch(name, *default) raise ArgumentError, 'wrong number of arguments' if default.length > 1 key = name.to_s return shells.fetch(key) if shells.has_key?(key) return yield(name) if block_given? return default.first if default.length == 1 raise KeyError, "unknown shell #{name.inspect} for machine #{machine.name}" end |
#key?(name) ⇒ Boolean Also known as: include?, member?
25 26 27 |
# File 'lib/osvm/shell_collection.rb', line 25 def key?(name) shells.has_key?(name.to_s) end |
#keys ⇒ Object
32 33 34 |
# File 'lib/osvm/shell_collection.rb', line 32 def keys shells.keys end |
#to_h ⇒ Object
40 41 42 |
# File 'lib/osvm/shell_collection.rb', line 40 def to_h shells.dup end |