Project

refr

0.0
No commit activity in last 3 years
No release in over 3 years
Simple reference implementation
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

 Project Readme

Simple Ruby reference

It's a really simple reference implementation, used in failirc.

>> require 'refr'
true
>> lol = 2
2
>> ref = Reference{:lol}
2
>> ref =~ "what"
"what"
>> lol
"what"

This is useful especially in an event dispatcher, you can use a reference object as it was the real object, the only stolen methods are: ___get_referenced___, ___set_referenced___, ~ and =~, everything else is sent to the referenced object.

You can also create a reference to an object directly with Reference.[]

Or you can use the Kernel#Reference helper to achieve both.

Cases where the Reference object doesn't work as expected

There are some situations where the Reference object doesn't work exactly as the object it's referencing, this cases are most likely related to C methods, when this happens just remember to use the ~ method on the reference to get the referenced object.

  • In the case statement when comparing for the object's class it doesn't work due to Module#=== being implemented in C.

  • IO#== and IO#=== don't work as expected, this happens to be a problem when using Array#delete with a referenced IO object.
    If you want to compare an IO object to a Reference:IO you have to do ref == io and not io == ref or it won't work correctly.
    Keep in mind that if the thing you compare with is a Reference:IO too you're not going to get what you're expecting, the comparing value has to be a real IO object.

  • Same of IO#== happens for Symbol

  • Some weird problems seem to happen when returning a Reference from a to_s method.

If you find any other situations where it's not working as expected open an issue or send me an email and I'll add it here.