[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

hook, or override const_set, and const_get

John Pywtorak

10/2/2007 9:43:00 PM

I have seen some examples of hooking into const_missing; Howerver, I
can't seem to find anything on const_set, and const_get, any ideas?

I tried opening class Module, ex.

class Module
def const_set(cname, cval)
....
end
end

Does not work. I realize this is very dangerous. Is there any other
way to intercept when, ex

FOO="bar"

happens?

Thanks

3 Answers

Eric Hodel

10/2/2007 10:40:00 PM

0

On Oct 2, 2007, at 14:43 , John Pywtorak wrote:
> I have seen some examples of hooking into const_missing; Howerver,
> I can't seem to find anything on const_set, and const_get, any ideas?
>
> I tried opening class Module, ex.
>
> class Module
> def const_set(cname, cval)
> ....
> end
> end
>
> Does not work. I realize this is very dangerous. Is there any
> other way to intercept when, ex
>
> FOO="bar"
>
> happens?

a) Edit variable.c

b) Run your code through a ruby2ruby subclass that wraps up your
const assignments with extra code.

--
Poor workers blame their tools. Good workers build better tools. The
best workers get their tools to do the work for them. -- Syndicate Wars



John Pywtorak

10/3/2007 1:06:00 AM

0

Eric Hodel wrote:
> On Oct 2, 2007, at 14:43 , John Pywtorak wrote:
>> I have seen some examples of hooking into const_missing; Howerver, I
>> can't seem to find anything on const_set, and const_get, any ideas?
>>
>> I tried opening class Module, ex.
>>
>> class Module
>> def const_set(cname, cval)
>> ....
>> end
>> end
>>
>> Does not work. I realize this is very dangerous. Is there any other
>> way to intercept when, ex
>>
>> FOO="bar"
>>
>> happens?
>
> a) Edit variable.c
>
> b) Run your code through a ruby2ruby subclass that wraps up your const
> assignments with extra code.
>

Thanks Eric. Option a makes me think I am taking the wrong approach.
Option b looks more attractive. Well at least I know I was not missing
something easier.

Eric Hodel

10/3/2007 7:46:00 AM

0

On Oct 2, 2007, at 18:05 , John Pywtorak wrote:
> Eric Hodel wrote:
>> On Oct 2, 2007, at 14:43 , John Pywtorak wrote:
>>> I have seen some examples of hooking into const_missing;
>>> Howerver, I can't seem to find anything on const_set, and
>>> const_get, any ideas?
>>>
>>> I tried opening class Module, ex.
>>>
>>> class Module
>>> def const_set(cname, cval)
>>> ....
>>> end
>>> end
>>>
>>> Does not work. I realize this is very dangerous. Is there any
>>> other way to intercept when, ex
>>>
>>> FOO="bar"
>>>
>>> happens?
>> a) Edit variable.c
>> b) Run your code through a ruby2ruby subclass that wraps up your
>> const assignments with extra code.
>
> Thanks Eric. Option a makes me think I am taking the wrong
> approach. Option b looks more attractive. Well at least I know I
> was not missing something easier.

Both options are pure evil and guaranteed to cause you pain.

What is your ultimate goal?

--
Poor workers blame their tools. Good workers build better tools. The
best workers get their tools to do the work for them. -- Syndicate Wars