# Labrador v0.0.1 or broken @ key

**URL:** <https://www.ruby-forum.com/t/labrador-v0-0-1-or-broken-key/106552>\
**Category:** Ruby\
**Created:** [June 11, 2007, 9:36pm UTC](https://www.ruby-forum.com/t/labrador-v0-0-1-or-broken-key/106552 "2007-06-11T21:36:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [June 11, 2007, 9:36pm UTC](https://www.ruby-forum.com/t/labrador-v0-0-1-or-broken-key/106552/1 "2007-06-11T21:36:26Z")

</div>

Hi list

I eventually decided to submit some code to Rubyforge, just waiting  
for the Rubyforge decision…

In the meantime I wanted to share some of the code to be released. It  
seems that Robert K. broke his “@” key 😉 so I decided to replace  
ivars in my Ruby.  
Closure based properties, here we go

PropertyIllegalMonitorState = Class::new RuntimeError  
class Module  
def property name, type = :rw, &blk  
props = {}  
define\_method name do  
props[object\_id] ||= blk.call if blk  
props[object\_id]  
end  
case type  
when :rw  
define\_method “#{name}=” do |val|  
props[object\_id] = val  
end  
when :const  
define\_method “#{name}=” do |val|  
raise PropertyIllegalMonitorState,  
“const property #{name} cannot be reassigned” if  
props.has\_key? object\_id  
props[object\_id] = val  
end # define\_method “#{name}=” do |val|  
end  
end  
end

Ideas? Believes? Opinions?  
Here is what I believe of it:

- Real const properties that cannot be circumvented by metaprogramming
- A different style never hurts
- Quite short code to achieve this
- Lots of place for development, locked properties to implement  
Critical Sections, access fine graining e.g.

- Way slower than ivars I guess (no time to benchmark so far)
- Python style property assignment on self cannot be avoided;  
self.prop = 42 not prop=42
- You will tell me 😉

BTW the rest of the package wil be enum trickery, things like  
%w{a b c}.map.succ =\> %w{ b c d }  
[\*1…10].map(:+, 2) =\> [\*3…12]

It is just for people who share my style (even if they do not like  
Labradors;).

Cheers  
Robert
