Ignore:
Timestamp:
Jul 9, 2020, 8:51:43 AM (4 years ago)
Author:
coas-nagasima
Message:

mrubyを2.1.1に更新

Location:
EcnlProtoTool/trunk/mruby-2.1.1
Files:
1 added
2 deleted
10 edited
1 moved

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/mruby-2.1.1/mrblib/00class.rb

    r331 r439  
    66  end
    77  # 15.2.2.4.11
    8   def attr(name)
    9     attr_reader(name)
    10   end
     8  alias attr attr_reader
     9  #def attr(name)
     10  #  attr_reader(name)
     11  #end
    1112
    1213  # 15.2.2.4.27
     
    1617      m.included(self)
    1718    end
     19    self
    1820  end
    1921
     
    2325      m.prepended(self)
    2426    end
     27    self
    2528  end
    2629end
  • EcnlProtoTool/trunk/mruby-2.1.1/mrblib/10error.rb

    r331 r439  
    33end
    44
    5 # ISO 15.2.25
    6 class LocalJumpError < StandardError
     5# ISO 15.2.25 says "LocalJumpError < StandardError"
     6class LocalJumpError < ScriptError
    77end
    88
     
    5252end
    5353
     54class FrozenError < RuntimeError
     55end
     56
    5457class StopIteration < IndexError
    5558  attr_accessor :result
  • EcnlProtoTool/trunk/mruby-2.1.1/mrblib/array.rb

    r331 r439  
     1# coding: utf-8
    12##
    23# Array
     
    1011  #
    1112  # ISO 15.2.12.5.10
    12   def each(&block)
    13     return to_enum :each unless block_given?
    14 
    15     idx = 0
    16     while idx < length
    17       block.call(self[idx])
    18       idx += 1
    19     end
    20     self
    21   end
     13  # def each(&block)
     14  #   return to_enum :each unless block
     15
     16  #   idx = 0
     17  #   while idx < length
     18  #     block.call(self[idx])
     19  #     idx += 1
     20  #   end
     21  #   self
     22  # end
    2223
    2324  ##
     
    2728  # ISO 15.2.12.5.11
    2829  def each_index(&block)
    29     return to_enum :each_index unless block_given?
     30    return to_enum :each_index unless block
    3031
    3132    idx = 0
     
    4445  # ISO 15.2.12.5.7
    4546  def collect!(&block)
    46     return to_enum :collect! unless block_given?
    47 
    48     self.each_index { |idx| self[idx] = block.call(self[idx]) }
     47    return to_enum :collect! unless block
     48
     49    idx = 0
     50    len = size
     51    while idx < len
     52      self[idx] = block.call self[idx]
     53      idx += 1
     54    end
    4955    self
    5056  end
     
    6167  # ISO 15.2.12.5.15
    6268  def initialize(size=0, obj=nil, &block)
    63     raise TypeError, "expected Integer for 1st argument" unless size.kind_of? Integer
     69    size = size.__to_int
    6470    raise ArgumentError, "negative array size" if size < 0
    6571
     
    7884  end
    7985
    80   def _inspect
    81     return "[]" if self.size == 0
    82     "["+self.map{|x|x.inspect}.join(", ")+"]"
     86  def _inspect(recur_list)
     87    size = self.size
     88    return "[]" if size == 0
     89    return "[...]" if recur_list[self.object_id]
     90    recur_list[self.object_id] = true
     91    ary=[]
     92    i=0
     93    while i<size
     94      ary<<self[i]._inspect(recur_list)
     95      i+=1
     96    end
     97    "["+ary.join(", ")+"]"
    8398  end
    8499  ##
     
    87102  # ISO 15.2.12.5.31 (x)
    88103  def inspect
    89     begin
    90       self._inspect
    91     rescue SystemStackError
    92       "[...]"
    93     end
     104    self._inspect({})
    94105  end
    95106  # ISO 15.2.12.5.32 (x)
     
    179190    ret
    180191  end
    181 
    182   # internal method to convert multi-value to single value
    183   def __svalue
    184     return self.first if self.size < 2
    185     self
    186   end
    187192end
    188193
     
    197202  # elements.
    198203  def sort!(&block)
    199     self.replace(self.sort(&block))
     204    stack = [ [ 0, self.size - 1 ] ]
     205    until stack.empty?
     206      left, mid, right = stack.pop
     207      if right == nil
     208        right = mid
     209        # sort self[left..right]
     210        if left < right
     211          if left + 1 == right
     212            lval = self[left]
     213            rval = self[right]
     214            cmp = if block then block.call(lval,rval) else lval <=> rval end
     215            if cmp.nil?
     216              raise ArgumentError, "comparison of #{lval.inspect} and #{rval.inspect} failed"
     217            end
     218            if cmp > 0
     219              self[left]  = rval
     220              self[right] = lval
     221            end
     222          else
     223            mid = ((left + right + 1) / 2).floor
     224            stack.push [ left, mid, right ]
     225            stack.push [ mid, right ]
     226            stack.push [ left, (mid - 1) ] if left < mid - 1
     227          end
     228        end
     229      else
     230        lary = self[left, mid - left]
     231        lsize = lary.size
     232
     233        # The entity sharing between lary and self may cause a large memory
     234        # copy operation in the merge loop below.  This harmless operation
     235        # cancels the sharing and provides a huge performance gain.
     236        lary[0] = lary[0]
     237
     238        # merge
     239        lidx = 0
     240        ridx = mid
     241        (left..right).each { |i|
     242          if lidx >= lsize
     243            break
     244          elsif ridx > right
     245            self[i, lsize - lidx] = lary[lidx, lsize - lidx]
     246            break
     247          else
     248            lval = lary[lidx]
     249            rval = self[ridx]
     250            cmp = if block then block.call(lval,rval) else lval <=> rval end
     251            if cmp.nil?
     252              raise ArgumentError, "comparison of #{lval.inspect} and #{rval.inspect} failed"
     253            end
     254            if cmp <= 0
     255              self[i] = lval
     256              lidx += 1
     257            else
     258              self[i] = rval
     259              ridx += 1
     260            end
     261          end
     262        }
     263      end
     264    end
     265    self
     266  end
     267
     268  def sort(&block)
     269    self.dup.sort!(&block)
    200270  end
    201271end
  • EcnlProtoTool/trunk/mruby-2.1.1/mrblib/enum.rb

    r331 r439  
    1414module Enumerable
    1515
     16  NONE = Object.new
     17
    1618  ##
    1719  # Call the given block for each element
     
    6466
    6567  ##
    66   # Call the given block for each element
    67   # which is yield by +each+. Return
    68   # +ifnone+ if no block value was true.
    69   # Otherwise return the first block value
    70   # which had was true.
     68  # Return the first element for which
     69  # value from the block is true. If no
     70  # object matches, calls +ifnone+ and
     71  # returns its result. Otherwise returns
     72  # +nil+.
    7173  #
    7274  # ISO 15.3.2.2.4
    7375  def detect(ifnone=nil, &block)
    74     ret = ifnone
     76    return to_enum :detect, ifnone unless block
     77
    7578    self.each{|*val|
    7679      if block.call(*val)
    77         ret = val.__svalue
    78         break
    79       end
    80     }
    81     ret
     80        return val.__svalue
     81      end
     82    }
     83    ifnone.call unless ifnone.nil?
    8284  end
    8385
     
    283285  # ISO 15.3.2.2.16
    284286  def partition(&block)
     287    return to_enum :partition unless block
     288
    285289    ary_T = []
    286290    ary_F = []
     
    303307  # ISO 15.3.2.2.17
    304308  def reject(&block)
     309    return to_enum :reject unless block
     310
    305311    ary = []
    306312    self.each{|*val|
     
    315321  # ISO 15.3.2.2.18
    316322  alias select find_all
    317 
    318   ##
    319   # TODO
    320   # Does this OK? Please test it.
    321   def __sort_sub__(sorted, work, src_ary, head, tail, &block)
    322     if head == tail
    323       sorted[head] = work[head] if src_ary == 1
    324       return
    325     end
    326 
    327     # on current step, which is a src ary?
    328     if src_ary == 0
    329       src, dst = sorted, work
    330     else
    331       src, dst = work, sorted
    332     end
    333 
    334     key = src[head]    # key value for dividing values
    335     i, j = head, tail  # position to store on the dst ary
    336 
    337     (head + 1).upto(tail){|idx|
    338       if ((block)? block.call(src[idx], key): (src[idx] <=> key)) > 0
    339         # larger than key
    340         dst[j] = src[idx]
    341         j -= 1
    342       else
    343         dst[i] = src[idx]
    344         i += 1
    345       end
    346     }
    347 
    348     sorted[i] = key
    349 
    350     # sort each sub-array
    351     src_ary = (src_ary + 1) % 2  # exchange a src ary
    352     __sort_sub__(sorted, work, src_ary, head, i - 1, &block) if i > head
    353     __sort_sub__(sorted, work, src_ary, i + 1, tail, &block) if i < tail
    354   end
    355 #  private :__sort_sub__
    356323
    357324  ##
     
    365332  # ISO 15.3.2.2.19
    366333  def sort(&block)
    367     ary = []
    368     self.each{|*val| ary.push(val.__svalue)}
    369     if ary.size > 1
    370       __sort_sub__(ary, ::Array.new(ary.size), 0, 0, ary.size - 1, &block)
    371     end
    372     ary
     334    self.map{|*val| val.__svalue}.sort(&block)
    373335  end
    374336
     
    384346    i = 0
    385347    self.each do |e|
    386       n = (e.hash & (0x7fffffff >> (i % 16))) << (i % 16)
    387       h ^= n
     348      h = __update_hash(h, i, e.hash)
    388349      i += 1
    389350    end
  • EcnlProtoTool/trunk/mruby-2.1.1/mrblib/hash.rb

    r331 r439  
    1313  def ==(hash)
    1414    return true if self.equal?(hash)
    15     begin
    16       hash = hash.to_hash
    17     rescue NoMethodError
     15    unless Hash === hash
    1816      return false
    1917    end
     
    3331  def eql?(hash)
    3432    return true if self.equal?(hash)
    35     begin
    36       hash = hash.to_hash
    37     rescue NoMethodError
     33    unless Hash === hash
    3834      return false
    3935    end
     
    5652  def delete(key, &block)
    5753    if block && !self.has_key?(key)
    58       block.call(key)
    59     else
    60       self.__delete(key)
    61     end
     54      return block.call(key)
     55    end
     56    self.__delete(key)
    6257  end
    6358
     
    8580  # ISO 15.2.13.4.9
    8681  def each(&block)
    87     return to_enum :each unless block_given?
     82    return to_enum :each unless block
    8883
    8984    keys = self.keys
     
    118113  # ISO 15.2.13.4.10
    119114  def each_key(&block)
    120     return to_enum :each_key unless block_given?
     115    return to_enum :each_key unless block
    121116
    122117    self.keys.each{|k| block.call(k)}
     
    144139  # ISO 15.2.13.4.11
    145140  def each_value(&block)
    146     return to_enum :each_value unless block_given?
     141    return to_enum :each_value unless block
    147142
    148143    self.keys.each{|k| block.call(self[k])}
     
    155150  # ISO 15.2.13.4.23
    156151  def replace(hash)
    157     raise TypeError, "can't convert argument into Hash" unless hash.respond_to?(:to_hash)
     152    raise TypeError, "Hash required (#{hash.class} given)" unless Hash === hash
    158153    self.clear
    159     hash = hash.to_hash
    160154    hash.each_key{|k|
    161155      self[k] = hash[k]
     
    180174  # ISO 15.2.13.4.22
    181175  def merge(other, &block)
    182     h = {}
    183     raise TypeError, "can't convert argument into Hash" unless other.respond_to?(:to_hash)
    184     other = other.to_hash
    185     self.each_key{|k| h[k] = self[k]}
     176    raise TypeError, "Hash required (#{other.class} given)" unless Hash === other
     177    h = self.dup
    186178    if block
    187179      other.each_key{|k|
     
    195187
    196188  # internal method for Hash inspection
    197   def _inspect
     189  def _inspect(recur_list)
    198190    return "{}" if self.size == 0
    199     "{"+self.map {|k,v|
    200       k._inspect + "=>" + v._inspect
    201     }.join(", ")+"}"
     191    return "{...}" if recur_list[self.object_id]
     192    recur_list[self.object_id] = true
     193    ary=[]
     194    keys=self.keys
     195    size=keys.size
     196    i=0
     197    while i<size
     198      k=keys[i]
     199      ary<<(k._inspect(recur_list) + "=>" + self[k]._inspect(recur_list))
     200      i+=1
     201    end
     202    "{"+ary.join(", ")+"}"
    202203  end
    203204  ##
     
    206207  # ISO 15.2.13.4.30 (x)
    207208  def inspect
    208     begin
    209       self._inspect
    210     rescue SystemStackError
    211       "{...}"
    212     end
     209    self._inspect({})
    213210  end
    214211  # ISO 15.2.13.4.31 (x)
     
    225222  #  1.8/1.9 Hash#reject! returns Hash; ISO says nothing.
    226223  #
    227   def reject!(&b)
    228     return to_enum :reject! unless block_given?
     224  def reject!(&block)
     225    return to_enum :reject! unless block
    229226
    230227    keys = []
    231228    self.each{|k,v|
    232       if b.call([k, v])
     229      if block.call([k, v])
    233230        keys.push(k)
    234231      end
     
    256253  #  1.8/1.9 Hash#reject returns Hash; ISO says nothing.
    257254  #
    258   def reject(&b)
    259     return to_enum :reject unless block_given?
     255  def reject(&block)
     256    return to_enum :reject unless block
    260257
    261258    h = {}
    262259    self.each{|k,v|
    263       unless b.call([k, v])
     260      unless block.call([k, v])
    264261        h[k] = v
    265262      end
     
    278275  #  1.9 Hash#select! returns Hash; ISO says nothing.
    279276  #
    280   def select!(&b)
    281     return to_enum :select! unless block_given?
     277  def select!(&block)
     278    return to_enum :select! unless block
    282279
    283280    keys = []
    284281    self.each{|k,v|
    285       unless b.call([k, v])
     282      unless block.call([k, v])
    286283        keys.push(k)
    287284      end
     
    309306  #  1.9 Hash#select returns Hash; ISO says nothing
    310307  #
    311   def select(&b)
    312     return to_enum :select unless block_given?
     308  def select(&block)
     309    return to_enum :select unless block
    313310
    314311    h = {}
    315312    self.each{|k,v|
    316       if b.call([k, v])
     313      if block.call([k, v])
    317314        h[k] = v
    318315      end
    319316    }
    320317    h
    321   end
    322 
    323   ##
    324   #  call-seq:
    325   #    hsh.rehash -> hsh
    326   #
    327   #  Rebuilds the hash based on the current hash values for each key. If
    328   #  values of key objects have changed since they were inserted, this
    329   #  method will reindex <i>hsh</i>.
    330   #
    331   #     h = {"AAA" => "b"}
    332   #     h.keys[0].chop!
    333   #     h          #=> {"AA"=>"b"}
    334   #     h["AA"]    #=> nil
    335   #     h.rehash   #=> {"AA"=>"b"}
    336   #     h["AA"]    #=> "b"
    337   #
    338   def rehash
    339     h = {}
    340     self.each{|k,v|
    341       h[k] = v
    342     }
    343     self.replace(h)
    344   end
    345 
    346   def __update(h)
    347     h.each_key{|k| self[k] = h[k]}
    348     self
    349318  end
    350319end
  • EcnlProtoTool/trunk/mruby-2.1.1/mrblib/kernel.rb

    r321 r439  
    77  # 15.3.1.2.1 Kernel.`
    88  # provided by Kernel#`
    9   # 15.3.1.3.5
     9  # 15.3.1.3.3
    1010  def `(s)
    1111    raise NotImplementedError.new("backquotes not implemented")
     
    4141
    4242  # internal method for inspect
    43   def _inspect
     43  def _inspect(_recur_list)
    4444    self.inspect
    4545  end
  • EcnlProtoTool/trunk/mruby-2.1.1/mrblib/mrblib.rake

    r321 r439  
    44  current_build_dir = "#{build_dir}/#{relative_from_root}"
    55
    6   self.libmruby << objfile("#{current_build_dir}/mrblib")
     6  self.libmruby_objs << objfile("#{current_build_dir}/mrblib")
    77
    88  file objfile("#{current_build_dir}/mrblib") => "#{current_build_dir}/mrblib.c"
    99  file "#{current_build_dir}/mrblib.c" => [mrbcfile, __FILE__] + Dir.glob("#{current_dir}/*.rb").sort do |t|
    1010    _, _, *rbfiles = t.prerequisites
    11     FileUtils.mkdir_p File.dirname(t.name)
     11    mkdir_p File.dirname(t.name)
    1212    open(t.name, 'w') do |f|
    1313      _pp "GEN", "*.rb", "#{t.name.relative_path}"
  • EcnlProtoTool/trunk/mruby-2.1.1/mrblib/numeric.rb

    r331 r439  
    4646  # ISO 15.2.8.3.15
    4747  def downto(num, &block)
    48     return to_enum(:downto, num) unless block_given?
     48    return to_enum(:downto, num) unless block
    4949
    5050    i = self.to_i
     
    7171  # ISO 15.2.8.3.22
    7272  def times &block
    73     return to_enum :times unless block_given?
     73    return to_enum :times unless block
    7474
    7575    i = 0
     
    8787  # ISO 15.2.8.3.27
    8888  def upto(num, &block)
    89     return to_enum(:upto, num) unless block_given?
     89    return to_enum(:upto, num) unless block
    9090
    9191    i = self.to_i
     
    103103  def step(num=nil, step=1, &block)
    104104    raise ArgumentError, "step can't be 0" if step == 0
    105     return to_enum(:step, num, step) unless block_given?
     105    return to_enum(:step, num, step) unless block
    106106
    107     i = if num.kind_of? Float then self.to_f else self end
    108     if num == nil
     107    i = __coerce_step_counter(num, step)
     108    if num == self || step.infinite?
     109      block.call(i) if step > 0 && i <= (num||i) || step < 0 && i >= (num||-i)
     110    elsif num == nil
    109111      while true
    110112        block.call(i)
    111         i+=step
     113        i += step
    112114      end
    113       return self
    114     end
    115     if step > 0
     115    elsif step > 0
    116116      while i <= num
    117117        block.call(i)
     
    162162  alias truncate floor
    163163end
    164 
    165 ##
    166 # Float
    167 #
    168 # ISO 15.2.9
    169 class Float
    170   # mruby special - since mruby integers may be upgraded to floats,
    171   # floats should be compatible to integers.
    172   include Integral
    173 end
  • EcnlProtoTool/trunk/mruby-2.1.1/mrblib/range.rb

    r331 r439  
    1111  # ISO 15.2.14.4.4
    1212  def each(&block)
    13     return to_enum :each unless block_given?
     13    return to_enum :each unless block
    1414
    1515    val = self.first
     
    2727    end
    2828
    29     if val.kind_of?(String) && last.kind_of?(String) # fixnums are special
     29    if val.kind_of?(String) && last.kind_of?(String) # strings are special
    3030      if val.respond_to? :upto
    3131        return val.upto(last, exclude_end?, &block)
  • EcnlProtoTool/trunk/mruby-2.1.1/mrblib/string.rb

    r331 r439  
    44# ISO 15.2.10
    55class String
     6  # ISO 15.2.10.3
    67  include Comparable
     8
    79  ##
    810  # Calls the given block for each line
     
    1012  #
    1113  # ISO 15.2.10.5.15
    12   def each_line(rs = "\n", &block)
    13     return to_enum(:each_line, rs, &block) unless block
    14     return block.call(self) if rs.nil?
    15     rs = rs.to_str
    16     offset = 0
    17     rs_len = rs.length
    18     this = dup
    19     while pos = this.index(rs, offset)
    20       block.call(this[offset, pos + rs_len - offset])
    21       offset = pos + rs_len
    22     end
    23     block.call(this[offset, this.size - offset]) if this.size > offset
     14  def each_line(separator = "\n", &block)
     15    return to_enum(:each_line, separator) unless block
     16
     17    if separator.nil?
     18      block.call(self)
     19      return self
     20    end
     21    raise TypeError unless separator.is_a?(String)
     22
     23    paragraph_mode = false
     24    if separator.empty?
     25      paragraph_mode = true
     26      separator = "\n\n"
     27    end
     28    start = 0
     29    string = dup
     30    self_len = length
     31    sep_len = separator.length
     32    should_yield_subclass_instances = self.class != String
     33
     34    while (pointer = string.index(separator, start))
     35      pointer += sep_len
     36      pointer += 1 while paragraph_mode && string[pointer] == "\n"
     37      if should_yield_subclass_instances
     38        block.call(self.class.new(string[start, pointer - start]))
     39      else
     40        block.call(string[start, pointer - start])
     41      end
     42      start = pointer
     43    end
     44    return self if start == self_len
     45
     46    if should_yield_subclass_instances
     47      block.call(self.class.new(string[start, self_len - start]))
     48    else
     49      block.call(string[start, self_len - start])
     50    end
    2451    self
    2552  end
     
    6895    end
    6996    if !replace.nil? || !block
    70       replace = replace.to_str
     97      replace.__to_str
    7198    end
    7299    offset = 0
     
    97124  # ISO 15.2.10.5.19
    98125  def gsub!(*args, &block)
    99     raise RuntimeError, "can't modify frozen String" if frozen?
     126    raise FrozenError, "can't modify frozen String" if frozen?
    100127    return to_enum(:gsub!, *args) if args.length == 1 && !block
    101128    str = self.gsub(*args, &block)
    102     return nil if str == self
     129    return nil unless self.index(args[0])
    103130    self.replace(str)
    104131  end
    105132
    106   ##
    107   # Calls the given block for each match of +pattern+
    108   # If no block is given return an array with all
    109   # matches of +pattern+.
    110   #
    111   # ISO 15.2.10.5.32
    112   def scan(reg, &block)
    113     ### *** TODO *** ###
    114     unless Object.const_defined?(:Regexp)
    115       raise NotImplementedError, "scan not available (yet)"
    116     end
    117   end
     133#  ##
     134#  # Calls the given block for each match of +pattern+
     135#  # If no block is given return an array with all
     136#  # matches of +pattern+.
     137  ##
     138#  # ISO 15.2.10.5.32
     139#  def scan(pattern, &block)
     140#    # TODO: String#scan is not implemented yet
     141#  end
    118142
    119143  ##
     
    130154
    131155    pattern, replace = *args
    132     pattern = pattern.to_str
     156    pattern.__to_str
    133157    if args.length == 2 && block
    134158      block = nil
    135159    end
    136     if !block
    137       replace = replace.to_str
     160    unless block
     161      replace.__to_str
    138162    end
    139163    result = []
     
    160184  # ISO 15.2.10.5.37
    161185  def sub!(*args, &block)
    162     raise RuntimeError, "can't modify frozen String" if frozen?
     186    raise FrozenError, "can't modify frozen String" if frozen?
    163187    str = self.sub(*args, &block)
    164     return nil if str == self
     188    return nil unless self.index(args[0])
    165189    self.replace(str)
    166   end
    167 
    168   ##
    169   # Call the given block for each character of
    170   # +self+.
    171   def each_char(&block)
    172     pos = 0
    173     while pos < self.size
    174       block.call(self[pos])
    175       pos += 1
    176     end
    177     self
    178190  end
    179191
     
    181193  # Call the given block for each byte of +self+.
    182194  def each_byte(&block)
     195    return to_enum(:each_byte, &block) unless block
    183196    bytes = self.bytes
    184197    pos = 0
     
    190203  end
    191204
    192   ##
    193   # Modify +self+ by replacing the content of +self+.
    194   # The portion of the string affected is determined using the same criteria as +String#[]+.
    195   def []=(*args)
    196     anum = args.size
    197     if anum == 2
    198       pos, value = args
    199       case pos
    200       when String
    201         posnum = self.index(pos)
    202         if posnum
    203           b = self[0, posnum.to_i]
    204           a = self[(posnum + pos.length)..-1]
    205           self.replace([b, value, a].join(''))
    206         else
    207           raise IndexError, "string not matched"
    208         end
    209       when Range
    210         head = pos.begin
    211         tail = pos.end
    212         tail += self.length if tail < 0
    213         unless pos.exclude_end?
    214           tail += 1
    215         end
    216         return self[head, tail-head]=value
    217       else
    218         pos += self.length if pos < 0
    219         if pos < 0 || pos > self.length
    220           raise IndexError, "index #{args[0]} out of string"
    221         end
    222         b = self[0, pos.to_i]
    223         a = self[pos + 1..-1]
    224         self.replace([b, value, a].join(''))
    225       end
    226       return value
    227     elsif anum == 3
    228       pos, len, value = args
    229       pos += self.length if pos < 0
    230       if pos < 0 || pos > self.length
    231         raise IndexError, "index #{args[0]} out of string"
    232       end
    233       if len < 0
    234         raise IndexError, "negative length #{len}"
    235       end
    236       b = self[0, pos.to_i]
    237       a = self[pos + len..-1]
    238       self.replace([b, value, a].join(''))
    239       return value
    240     else
    241       raise ArgumentError, "wrong number of arguments (#{anum} for 2..3)"
    242     end
    243   end
    244 
     205  # those two methods requires Regexp that is optional in mruby
    245206  ##
    246207  # ISO 15.2.10.5.3
    247   def =~(re)
    248     raise TypeError, "type mismatch: String given" if re.respond_to? :to_str
    249     re =~ self
    250   end
     208  #def =~(re)
     209  # re =~ self
     210  #end
    251211
    252212  ##
    253213  # ISO 15.2.10.5.27
    254   def match(re, &block)
    255     if re.respond_to? :to_str
    256       if Object.const_defined?(:Regexp)
    257         r = Regexp.new(re)
    258         r.match(self, &block)
    259       else
    260         raise NotImplementedError, "String#match needs Regexp class"
    261       end
    262     else
    263       re.match(self, &block)
    264     end
    265   end
     214  #def match(re, &block)
     215  #  re.match(self, &block)
     216  #end
    266217end
    267 
    268 ##
    269 # String is comparable
    270 #
    271 # ISO 15.2.10.3
    272 module Comparable; end
    273 class String
    274   include Comparable
    275 end
Note: See TracChangeset for help on using the changeset viewer.