- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-1.3.0
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-array-ext/mrblib/array.rb
r321 r331 1 1 class Array 2 ## 3 # call-seq: 4 # Array.try_convert(obj) -> array or nil 5 # 6 # Tries to convert +obj+ into an array, using +to_ary+ method. 7 # converted array or +nil+ if +obj+ cannot be converted for any reason. 8 # This method can be used to check if an argument is an array. 9 # 10 # Array.try_convert([1]) #=> [1] 11 # Array.try_convert("1") #=> nil 12 # 13 # if tmp = Array.try_convert(arg) 14 # # the argument is an array 15 # elsif tmp = String.try_convert(arg) 16 # # the argument is a string 17 # end 18 # 19 def self.try_convert(obj) 20 if obj.respond_to?(:to_ary) 21 obj.to_ary 22 else 23 nil 24 end 25 end 26 2 27 ## 3 28 # call-seq: … … 251 276 # 252 277 # Alternatively, if a block is given it will only be executed when an 253 # invalid +index+ is referenced. Negative values of +index+ count from the 254 # end of the array. 278 # invalid +index+ is referenced. 279 # 280 # Negative values of +index+ count from the end of the array. 255 281 # 256 282 # a = [ 11, 22, 33, 44 ] … … 710 736 nil 711 737 end 738 739 ## 740 # call-seq: 741 # ary.to_ary -> ary 742 # 743 # Returns +self+. 744 # 745 def to_ary 746 self 747 end 748 749 ## 750 # call-seq: 751 # ary.dig(idx, ...) -> object 752 # 753 # Extracts the nested value specified by the sequence of <i>idx</i> 754 # objects by calling +dig+ at each step, returning +nil+ if any 755 # intermediate step is +nil+. 756 # 757 def dig(idx,*args) 758 n = self[idx] 759 if args.size > 0 760 n&.dig(*args) 761 else 762 n 763 end 764 end 712 765 end
Note:
See TracChangeset
for help on using the changeset viewer.