| Class | Object |
| In: |
reference.rb
|
| Parent: | Object |
Provides an easy way to create a Reference. There are several ways to do it:
Here are some examples:
require 'reference'
a = ("a".."h").to_a # ["a", "b", "c", "d", "e", "f", "g", "h"]
b = a # b and a have the same object
p = ref{:a} # reference to the variable :a
q = a.ref # reference to the object in a
r = ref{"a[4]"} # reference to the assignable expression a[4]
s = a.ref[4] # reference to the [4] attribute of a
t = a.ref.[](4) # same
u = a.ref(:"[]",:"[]=",4) # same except set/get method names are explicit
v = a.ref([:"[]",4],[:"[]=",4]) # same except arguments are explicit
p[] # ["a", "b", "c", "d", "e", "f", "g", "h"]
p[] = (0..7).to_a # [0, 1, 2, 3, 4, 5, 6, 7]
a # [0, 1, 2, 3, 4, 5, 6, 7]
b # ["a", "b", "c", "d", "e", "f", "g", "h"]
q[] # ["a", "b", "c", "d", "e", "f", "g", "h"]
q[] = (-7..0).to_a # [-7, -6, -5, -4, -3, -2, -1, 0]
a # [0, 1, 2, 3, 4, 5, 6, 7]
b # [-7, -6, -5, -4, -3, -2, -1, 0]
r[] # 4
r[] = "r" # "r"
a # [0, 1, 2, 3, "r", 5, 6, 7]
b # [-7, -6, -5, -4, -3, -2, -1, 0]
# extra arg is slice length
s[2] # [-3, -2]
s[2] = ["s"] # ["s"]
a # [0, 1, 2, 3, "r", 5, 6, 7]
b # [-7, -6, -5, -4, "s", -1, 0]
t[] # "s"
t[] = "t" # "t"
a # [0, 1, 2, 3, "r", 5, 6, 7]
b # [-7, -6, -5, -4, "t", -1, 0]
u[] # "t"
u[] = "t" # "u"
a # [0, 1, 2, 3, "r", 5, 6, 7]
b # [-7, -6, -5, -4, "u", -1, 0]
v[] # "t"
v[] = "t" # "v"
a # [0, 1, 2, 3, "r", 5, 6, 7]
b # [-7, -6, -5, -4, "v", -1, 0]