Class: PyCall::Dict
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #delete(key) ⇒ Object
- #each(&block) ⇒ Object
- #has_key?(key) ⇒ Boolean (also: #include?, #key?, #member?)
- #length ⇒ Object
- #to_h ⇒ Object
Class Method Details
.new(h) ⇒ Object
8 9 10 |
# File 'lib/pycall/dict.rb', line 8 def self.new(h) super(h, {}) end |
Instance Method Details
#[](key) ⇒ Object
24 25 26 27 28 |
# File 'lib/pycall/dict.rb', line 24 def [](key) super rescue PyError nil end |
#delete(key) ⇒ Object
30 31 32 33 34 |
# File 'lib/pycall/dict.rb', line 30 def delete(key) v = self[key] LibPython::Helpers.delitem(__pyptr__, key) v end |
#each(&block) ⇒ Object
36 37 38 39 40 |
# File 'lib/pycall/dict.rb', line 36 def each(&block) return enum_for unless block_given? LibPython::Helpers.dict_each(__pyptr__, &block) self end |
#has_key?(key) ⇒ Boolean Also known as: include?, key?, member?
16 17 18 |
# File 'lib/pycall/dict.rb', line 16 def has_key?(key) LibPython::Helpers.dict_contains(__pyptr__, key) end |
#to_h ⇒ Object
42 43 44 45 46 |
# File 'lib/pycall/dict.rb', line 42 def to_h inject({}) do |h, (k, v)| h.update(k => v) end end |