S
Stephan Kämper
Hi all,
yesterday at work I tried to program this: Read a simple (YAML) file
contaning key values pairs and create an object which has accessor
methods for each pair, the key name being the method name.
All went well until I realised that I'd have to treat integer values in
a slightly special way. No problem I thought, evaluate
Integer( current_value )
and if that doesn't raise an exception, go ahead...
To my surprise the Symbols dissappeared and there were ints instead.
irb(main):001:0> Integer ops
=> 23417
Why doesn't that rains an exception?
I alwasy thought Symbols were closer to Strings than Integers (resp.
Fixnums), but I might have been wrong.
What's the reason for this behaviour?
I now that there's a unique int associated to each Symbol, but I still
think that a String like "42" IS more like an Integer, than
:a_symbol_like_this.
Happy rubying
Stephan
yesterday at work I tried to program this: Read a simple (YAML) file
contaning key values pairs and create an object which has accessor
methods for each pair, the key name being the method name.
All went well until I realised that I'd have to treat integer values in
a slightly special way. No problem I thought, evaluate
Integer( current_value )
and if that doesn't raise an exception, go ahead...
To my surprise the Symbols dissappeared and there were ints instead.
irb(main):001:0> Integer ops
=> 23417
Why doesn't that rains an exception?
I alwasy thought Symbols were closer to Strings than Integers (resp.
Fixnums), but I might have been wrong.
What's the reason for this behaviour?
I now that there's a unique int associated to each Symbol, but I still
think that a String like "42" IS more like an Integer, than
:a_symbol_like_this.
Happy rubying
Stephan