Class: Struct
- Defined in:
- ext/enterprise_script_service/mruby/mrbgems/mruby-struct/mrblib/struct.rb
Direct Known Subclasses
MRuby::Build::Exts, MRuby::Gem::LinkerConfig, ScriptCore::Result, ScriptCore::Stat
Instance Method Summary collapse
- #_inspect(recur_list) ⇒ Object
-
#dig(idx, *args) ⇒ Object
call-seq: hsh.dig(key,…) -> object.
-
#each(&block) ⇒ Object
Calls the given block for each element of
self
and pass the respective element. -
#each_pair(&block) ⇒ Object
Calls the given block for each element of
self
and pass the name and value of the respectiev element. -
#inspect ⇒ Object
(also: #to_s)
call-seq: struct.to_s -> string struct.inspect -> string.
-
#select(&block) ⇒ Object
Calls the given block for each element of
self
and returns an array with all elements of which block is not false.
Instance Method Details
permalink #_inspect(recur_list) ⇒ Object
[View source]
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-struct/mrblib/struct.rb', line 49 def _inspect(recur_list) return "#<struct #{self.class}:...>" if recur_list[self.object_id] recur_list[self.object_id] = true name = self.class.to_s if name[0] == "#" str = "#<struct " else str = "#<struct #{name} " end buf = [] self.each_pair do |k,v| buf.push k.to_s + "=" + v._inspect(recur_list) end str + buf.join(", ") + ">" end |
permalink #dig(idx, *args) ⇒ Object
call-seq:
hsh.dig(key,...) -> object
Extracts the nested value specified by the sequence of key objects by calling dig
at each step, returning nil
if any intermediate step is nil
.
91 92 93 94 95 96 97 98 |
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-struct/mrblib/struct.rb', line 91 def dig(idx,*args) n = self[idx] if args.size > 0 n&.dig(*args) else n end end |
permalink #each(&block) ⇒ Object
Calls the given block for each element of self
and pass the respective element.
ISO 15.2.18.4.4
14 15 16 17 18 19 |
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-struct/mrblib/struct.rb', line 14 def each(&block) self.class.members.each{|field| block.call(self[field]) } self end |
permalink #each_pair(&block) ⇒ Object
Calls the given block for each element of self
and pass the name and value of the respectiev element.
ISO 15.2.18.4.5
27 28 29 30 31 32 |
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-struct/mrblib/struct.rb', line 27 def each_pair(&block) self.class.members.each{|field| block.call(field.to_sym, self[field]) } self end |
permalink #inspect ⇒ Object Also known as: to_s
call-seq:
struct.to_s -> string
struct.inspect -> string
Describe the contents of this struct in a string.
15.2.18.4.10(x)
74 75 76 |
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-struct/mrblib/struct.rb', line 74 def inspect self._inspect({}) end |
permalink #select(&block) ⇒ Object
Calls the given block for each element of self
and returns an array with all elements of which block is not false.
ISO 15.2.18.4.7
40 41 42 43 44 45 46 47 |
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-struct/mrblib/struct.rb', line 40 def select(&block) ary = [] self.class.members.each{|field| val = self[field] ary.push(val) if block.call(val) } ary end |