Ok thanks - so I have to emulate it ;+)
And number two - which lowlevel-methods are used if array-elements are read
btw set (existing or new filled with value) (e.g. using push, slice, each)?
bye Berg
···
Am 03.02.2016 20:14 schrieb "Robert Klemme" <shortcutter@googlemail.com>:
On Wed, Feb 3, 2016 at 2:29 PM, A Berger <aberger7890@gmail.com> wrote:
> Hello
> How can I get the name of the object (self)?
> x=[1,2,3]; y[0]=x; y[0].name # => :x
You can't. Btw. this has been discussed numerous times before - even
years ago. The 5s explanation is that there can be unlimited number of
references to an object thus _the_ name does not exist.
> I want to modify setting and getting of array-elements,
> e.g. to store x**2 and to get sqrt(x), if so uses special array-names
> /^two_.*/
> (This is just an example)
> Which methods to change? Is that possible in Ruby?
> idea: overwrite Array.new: if objectmame matches, add math+super to
> object.which_methods???
I am not sure I fully understand what you are trying to do. But I am
pretty sure that it is a bad idea to fiddle with Array methods. It
seems a better idea to create a class that looks like an Array on the
surface and works differently internally.
Cheers
robert
···
On Wed, Feb 3, 2016 at 9:01 PM, A Berger <aberger7890@gmail.com> wrote:
Am 03.02.2016 20:14 schrieb "Robert Klemme" <shortcutter@googlemail.com>:
On Wed, Feb 3, 2016 at 2:29 PM, A Berger <aberger7890@gmail.com> wrote:
> I want to modify setting and getting of array-elements,
> e.g. to store x**2 and to get sqrt(x), if so uses special array-names
> /^two_.*/
> (This is just an example)
> Which methods to change? Is that possible in Ruby?
> idea: overwrite Array.new: if objectmame matches, add math+super to
> object.which_methods???
And number two - which lowlevel-methods are used if array-elements are read
btw set (existing or new filled with value) (e.g. using push, slice, each)?
bye Berg
>> > I want to modify setting and getting of array-elements,
>> > e.g. to store x**2 and to get sqrt(x), if so uses special array-names
>> > /^two_.*/
>> > (This is just an example)
>> > Which methods to change? Is that possible in Ruby?
>> > idea: overwrite Array.new: if objectmame matches, add math+super to
>> > object.which_methods???
better class My_Array < Array
> And number two - which lowlevel-methods are used if array-elements are
read
> btw set (existing or new filled with value) (e.g. using push, slice,
each)?
CORR: for using push => which are used by push,... ?
is there one (two) method(s) for setting+getting the value of each element?
(independant how the value is set/read)
I am not sure I fully understand what you are trying to do. But I am
pretty sure that it is a bad idea to fiddle with Array methods. It
seems a better idea to create a class that looks like an Array on the
surface and works differently internally.
Background is to do locking+inform other process if a value changes. So it
should be "low-level".
Although its not nice, which methods can be used?
thanks,
Berg
···
Am 03.02.2016 23:32 schrieb "Robert Klemme" <shortcutter@googlemail.com>:
On Wed, Feb 3, 2016 at 9:01 PM, A Berger <aberger7890@gmail.com> wrote:
> Am 03.02.2016 20:14 schrieb "Robert Klemme" <shortcutter@googlemail.com >:
>> On Wed, Feb 3, 2016 at 2:29 PM, A Berger <aberger7890@gmail.com> wrote: