Class: XArray
Overview
need to figure out how left and right things work …
OK this is cool, things on the right if more than one go in one array
... or a non-array if just one item
Constant Summary
collapse
- LAM_ISORT =
lambda {|a,b| a.inspect <=> b.inspect }
- LAM_SSORT =
lambda {|a,b| a.to_s <=> b.to_s }
Instance Method Summary
collapse
Methods inherited from ValueAdd
bestow_methods, capture_base_methods
Methods inherited from Value
#!=, #==, #ensure_valid, #freeze, freeze_raise?, ignore_on_freeze, #inspect, #prim_value, raise_on_freeze, #replace, #to_s, #to_wrapper, #type_of?, #unwrap, #val, #val=, #wrapped?, #~
Constructor Details
#initialize(obj = []) ⇒ XArray
Returns a new instance of XArray.
960
961
962
963
964
|
# File 'lib/primitive_wrapper.rb', line 960
def initialize(obj=[])
obj = obj.prim_value
ensure_valid(obj)
@value = obj
end
|
Instance Method Details
#[](*list) ⇒ Object
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
|
# File 'lib/primitive_wrapper.rb', line 983
def [](*list)
list = PrimitiveWrapper::get_list(list,size)
if list.empty?
return nil
elsif list.count==1
if list.first == :all
return @value
elsif list.first.type_of? Range
rtn = []
list.first.to_wrapper.re_range(size).each do |idx|
rtn.push @value[idx]
end
return rtn
else
return @value[list.first]
end
end
rtn = []
list.each do |ii|
if ii.type_of? Range
ii.to_wrapper.re_range(size).each do |idx|
rtn.push @value[idx]
end
elsif ii.type_of? Array
ii.each do |idx|
rtn.push @value[idx]
end
else
rtn.push @value[ii]
end
end
return rtn
end
|
#[]=(*list) ⇒ Object
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
|
# File 'lib/primitive_wrapper.rb', line 1017
def []=(*list)
data = list.pop
list = PrimitiveWrapper::get_list(list,size)
return nil if list.empty?
if list.count==1
if list.first.respond_to? :each
list = list.first
if list.type_of? Range
list = list.to_xr.re_range(size)
end
end
end
if list.count==1
if list.first == :all
PrimitiveWrapper.copy(@value, data, :all)
end
idxs = list.first
if (idxs.respond_to? :each)
if idxs.type_of? Range
idxs = idxs.to_xr.re_range(size)
end
idxs.each do |idx|
@value[idx] = data
end
else
@value[idxs] = data
end
else
if data.type_of? Array
data = PrimitiveWrapper::get_list(data,size)
end
PrimitiveWrapper.copy(@value, data, list)
end
end
|
#delete_at(*index_list) ⇒ Object
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
|
# File 'lib/primitive_wrapper.rb', line 1051
def delete_at(*index_list)
return nil if index_list.empty?
if (index_list.count==1)
if index_list.first==:all
self.empty!
end
else
list = PrimitiveWrapper::get_list(index_list,size)
rtn = []
list.sort.reverse.each do |idx|
rtn.push = @value.delete_at(idx)
end
return rtn
end
end
|
#include?(*list) ⇒ Boolean
replace with list of stuff
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
|
# File 'lib/primitive_wrapper.rb', line 1066
def include?(*list)
if list.count==1
if list.first.respond_to? :each
list = list.first
end
end
list.each do |item|
return false unless @value.include? item
end
true
end
|
#include_any?(*list) ⇒ Boolean
replace with list of stuff
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
|
# File 'lib/primitive_wrapper.rb', line 1077
def include_any?(*list)
if list.count==1
if list.first.respond_to? :each
list = list.first
end
end
list.each do |item|
return true if @value.include? item
end
false
end
|
971
972
973
|
# File 'lib/primitive_wrapper.rb', line 971
def isort
@value.sort &LAM_ISORT
end
|
974
975
976
|
# File 'lib/primitive_wrapper.rb', line 974
def isort!
@value.sort! &LAM_ISORT
end
|
977
978
979
|
# File 'lib/primitive_wrapper.rb', line 977
def ssort
@value.sort &LAM_SSORT
end
|
980
981
982
|
# File 'lib/primitive_wrapper.rb', line 980
def ssort!
@value.sort! &LAM_SSORT
end
|
#valid_type(prm) ⇒ Object
966
967
968
969
970
|
# File 'lib/primitive_wrapper.rb', line 966
def valid_type(prm)
return true if prm.kind_of? Array
return true if prm.kind_of? XArray
false
end
|