Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Interger( a_symbol ) raises no exception

Reply
Thread Tools

Interger( a_symbol ) raises no exception

 
 
Stephan Kämper
Guest
Posts: n/a
 
      11-11-2005
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
 
Reply With Quote
 
 
 
 
Martin DeMello
Guest
Posts: n/a
 
      11-11-2005
Stephan Kämper <(E-Mail Removed)> wrote:
>
> 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.


Not to mention

irb(main):001:0> Integer :"42"
=> 15665

martin
 
Reply With Quote
 
 
 
 
Eric Hodel
Guest
Posts: n/a
 
      11-11-2005
On Nov 10, 2005, at 10:52 PM, Stephan K=E4mper wrote:

> irb(main):001:0> Integer ops
> =3D> 23417
>
> Why doesn't that rains an exception?
> I alwasy thought Symbols were closer to Strings than Integers =20
> (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 =20
> still think that a String like "42" IS more like an Integer, =20
> than :a_symbol_like_this.


Symbols were originally just numbers, so they have #to_int defined =20
for backwards compatibility.

--=20
Eric Hodel - http://www.velocityreviews.com/forums/(E-Mail Removed) - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04




 
Reply With Quote
 
Yukihiro Matsumoto
Guest
Posts: n/a
 
      11-11-2005
Hi,

In message "Re: Interger( a_symbol ) raises no exception"
on Fri, 11 Nov 2005 18:04:45 +0900, Eric Hodel <(E-Mail Removed)> writes:

|Symbols were originally just numbers, so they have #to_int defined
|for backwards compatibility.

Until 1.8. 1.9 symbols does not have to_int any longer.

matz.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: shutil.rmtree raises "OSError: [Errno 39] Directory not empty"exception Tim Chase Python 1 07-13-2009 12:03 AM
Re: Undocumented Python 2.6 change: Py_None vs NULL when Cimplementation raises exception Fredrik Lundh Python 0 07-23-2008 07:45 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
Float-to-string conversion that raises exception instead of returning0.0 like atof Trond Valen C++ 20 12-07-2005 10:03 AM
PIL always raises "unrecognized image mode" exception with putdata() Noah Python 3 02-14-2004 05:54 AM



Advertisments