Ignore:
Timestamp:
Jan 21, 2018, 12:10:09 AM (6 years ago)
Author:
coas-nagasima
Message:

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

Location:
EcnlProtoTool/trunk/mruby-1.3.0
Files:
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-hash-ext/mrblib/hash.rb

    r321 r331  
    2929      o = object[0]
    3030      if o.respond_to?(:to_hash)
    31         h = Hash.new
     31        h = self.new
    3232        object[0].to_hash.each { |k, v| h[k] = v }
    3333        return h
    3434      elsif o.respond_to?(:to_a)
    35         h = Hash.new
     35        h = self.new
    3636        o.to_a.each do |i|
    3737          raise ArgumentError, "wrong element type #{i.class} (expected array)" unless i.respond_to?(:to_a)
     
    5454      raise ArgumentError, 'odd number of arguments for Hash'
    5555    end
    56     h = Hash.new
     56    h = self.new
    5757    0.step(length - 2, 2) do |i|
    5858      h[object[i]] = object[i + 1]
    5959    end
    6060    h
     61  end
     62
     63  ##
     64  # call-seq:
     65  #     Hash.try_convert(obj) -> hash or nil
     66  #
     67  # Try to convert <i>obj</i> into a hash, using to_hash method.
     68  # Returns converted hash or nil if <i>obj</i> cannot be converted
     69  # for any reason.
     70  #
     71  #     Hash.try_convert({1=>2})   # => {1=>2}
     72  #     Hash.try_convert("1=>2")   # => nil
     73  #
     74  def self.try_convert(obj)
     75    if obj.respond_to?(:to_hash)
     76      obj.to_hash
     77    else
     78      nil
     79    end
    6180  end
    6281
     
    193212
    194213  def invert
    195     h = Hash.new
     214    h = self.class.new
    196215    self.each {|k, v| h[v] = k }
    197216    h
     
    347366    }
    348367  end
     368
     369  ##
     370  # call-seq:
     371  #   hsh.dig(key,...)                 -> object
     372  #
     373  # Extracts the nested value specified by the sequence of <i>key</i>
     374  # objects by calling +dig+ at each step, returning +nil+ if any
     375  # intermediate step is +nil+.
     376  #
     377  def dig(idx,*args)
     378    n = self[idx]
     379    if args.size > 0
     380      n&.dig(*args)
     381    else
     382      n
     383    end
     384  end
    349385end
  • EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-hash-ext/src/hash-ext.c

    r321 r331  
    55*/
    66
    7 #include "mruby.h"
    8 #include "mruby/array.h"
    9 #include "mruby/hash.h"
     7#include <mruby.h>
     8#include <mruby/array.h>
     9#include <mruby/hash.h>
    1010
    1111/*
  • EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-hash-ext/test/hash.rb

    r321 r331  
    3838    Hash['d_key']
    3939  end
     40end
     41
     42assert('Hash.[] for sub class') do
     43  sub_hash_class = Class.new(Hash)
     44  sub_hash = sub_hash_class[]
     45  assert_equal(sub_hash_class, sub_hash.class)
     46end
     47
     48assert('Hash.try_convert') do
     49  assert_nil Hash.try_convert(nil)
     50  assert_nil Hash.try_convert("{1=>2}")
     51  assert_equal({1=>2}, Hash.try_convert({1=>2}))
    4052end
    4153
     
    138150end
    139151
     152assert("Hash#invert with sub class") do
     153  sub_hash_class = Class.new(Hash)
     154  sub_hash = sub_hash_class.new
     155  assert_equal(sub_hash_class, sub_hash.invert.class)
     156end
     157
    140158assert("Hash#keep_if") do
    141159  h = { 1 => 2, 3 => 4, 5 => 6 }
     
    231249  assert_false(h2 > h2)
    232250end
     251
     252assert("Hash#dig") do
     253  h = {a:{b:{c:1}}}
     254  assert_equal(1, h.dig(:a, :b, :c))
     255  assert_nil(h.dig(:d))
     256end
Note: See TracChangeset for help on using the changeset viewer.