Last change
on this file since 331 was 331, checked in by coas-nagasima, 6 years ago |
prototoolに関連するプロジェクトをnewlibからmuslを使うよう変更・更新
ntshellをnewlibの下位の実装から、muslのsyscallの実装に変更・更新
以下のOSSをアップデート
・mruby-1.3.0
・musl-1.1.18
・onigmo-6.1.3
・tcc-0.9.27
以下のOSSを追加
・openssl-1.1.0e
・curl-7.57.0
・zlib-1.2.11
以下のmrbgemsを追加
・iij/mruby-digest
・iij/mruby-env
・iij/mruby-errno
・iij/mruby-iijson
・iij/mruby-ipaddr
・iij/mruby-mock
・iij/mruby-require
・iij/mruby-tls-openssl
|
-
Property svn:eol-style
set to
native
-
Property svn:mime-type
set to
text/x-ruby;charset=UTF-8
|
File size:
2.0 KB
|
Rev | Line | |
---|
[270] | 1 | ##
|
---|
| 2 | # Struct
|
---|
| 3 | #
|
---|
| 4 | # ISO 15.2.18
|
---|
| 5 |
|
---|
| 6 | if Object.const_defined?(:Struct)
|
---|
| 7 | class Struct
|
---|
| 8 |
|
---|
| 9 | ##
|
---|
| 10 | # Calls the given block for each element of +self+
|
---|
| 11 | # and pass the respective element.
|
---|
| 12 | #
|
---|
| 13 | # ISO 15.2.18.4.4
|
---|
| 14 | def each(&block)
|
---|
| 15 | self.class.members.each{|field|
|
---|
| 16 | block.call(self[field])
|
---|
| 17 | }
|
---|
| 18 | self
|
---|
| 19 | end
|
---|
| 20 |
|
---|
| 21 | ##
|
---|
| 22 | # Calls the given block for each element of +self+
|
---|
| 23 | # and pass the name and value of the respectiev
|
---|
| 24 | # element.
|
---|
| 25 | #
|
---|
| 26 | # ISO 15.2.18.4.5
|
---|
| 27 | def each_pair(&block)
|
---|
| 28 | self.class.members.each{|field|
|
---|
| 29 | block.call(field.to_sym, self[field])
|
---|
| 30 | }
|
---|
| 31 | self
|
---|
| 32 | end
|
---|
| 33 |
|
---|
| 34 | ##
|
---|
| 35 | # Calls the given block for each element of +self+
|
---|
| 36 | # and returns an array with all elements of which
|
---|
| 37 | # block is not false.
|
---|
| 38 | #
|
---|
| 39 | # ISO 15.2.18.4.7
|
---|
| 40 | def select(&block)
|
---|
| 41 | ary = []
|
---|
| 42 | self.class.members.each{|field|
|
---|
| 43 | val = self[field]
|
---|
| 44 | ary.push(val) if block.call(val)
|
---|
| 45 | }
|
---|
| 46 | ary
|
---|
| 47 | end
|
---|
| 48 |
|
---|
| 49 | def _inspect
|
---|
| 50 | name = self.class.to_s
|
---|
| 51 | if name[0] == "#"
|
---|
| 52 | str = "#<struct "
|
---|
| 53 | else
|
---|
| 54 | str = "#<struct #{name} "
|
---|
| 55 | end
|
---|
| 56 | buf = []
|
---|
| 57 | self.each_pair do |k,v|
|
---|
| 58 | buf.push [k.to_s + "=" + v._inspect]
|
---|
| 59 | end
|
---|
| 60 | str + buf.join(", ") + ">"
|
---|
| 61 | end
|
---|
| 62 |
|
---|
| 63 | ##
|
---|
| 64 | # call-seq:
|
---|
| 65 | # struct.to_s -> string
|
---|
| 66 | # struct.inspect -> string
|
---|
| 67 | #
|
---|
| 68 | # Describe the contents of this struct in a string.
|
---|
| 69 | #
|
---|
| 70 | # 15.2.18.4.10(x)
|
---|
| 71 | #
|
---|
| 72 | def inspect
|
---|
| 73 | begin
|
---|
| 74 | self._inspect
|
---|
| 75 | rescue SystemStackError
|
---|
| 76 | "#<struct #{self.class.to_s}:...>"
|
---|
| 77 | end
|
---|
| 78 | end
|
---|
| 79 |
|
---|
| 80 | ##
|
---|
| 81 | # 15.2.18.4.11(x)
|
---|
| 82 | #
|
---|
| 83 | alias to_s inspect
|
---|
| 84 | end
|
---|
[331] | 85 |
|
---|
| 86 | ##
|
---|
| 87 | # call-seq:
|
---|
| 88 | # hsh.dig(key,...) -> object
|
---|
| 89 | #
|
---|
| 90 | # Extracts the nested value specified by the sequence of <i>key</i>
|
---|
| 91 | # objects by calling +dig+ at each step, returning +nil+ if any
|
---|
| 92 | # intermediate step is +nil+.
|
---|
| 93 | #
|
---|
| 94 | def dig(idx,*args)
|
---|
| 95 | n = self[idx]
|
---|
| 96 | if args.size > 0
|
---|
| 97 | n&.dig(*args)
|
---|
| 98 | else
|
---|
| 99 | n
|
---|
| 100 | end
|
---|
| 101 | end
|
---|
[270] | 102 | end
|
---|
| 103 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.