From: corey konrad <0011@...> Date: 2006-05-12T11:27:29+09:00 Subject: Re: conversion issues how about this cin>> = num, lol i dont know ruby seems like a trade off to me so far. i am just trying to understand all this hype about it. I mean every book i am reading says its the best most awesome easiest to use, just like using natural language, its elegant and beautiful and it will make you cry because its so easy to use, etc etc. I am having a hard time understanding that. If its true i would like to see it at some point. Mike Stok wrote: > On 11-May-06, at 9:53 PM, corey konrad wrote: > >>> because it needs to be a string when you print it. >> >> oh ok that makes sense, isnt there a getn method for getting number or >> other data types or do i always have to use gets? > > You can use something like: > > num = Integer(STDIN.gets) rescue nil > > or > > num = Float(STDIN.gets) rescue nil > > which do conversions and deal with trailing garbage. > > ratdog:~ mike$ irb > irb(main):001:0> Integer(" 0xE84C\n") > => 59468 > > I use these in quick and dirty scripts quite often, whether it's good > form I don't know :-) > > Mike > > -- > > Mike Stok > http://www.stok.ca/~mike/ > > The "`Stok' disclaimers" apply. -- Posted via http://www.ruby-forum.com/.