Hi, Am Dienstag, 28. Jul 2009, 02:16:44 +0900 schrieb Matthew K. Williams: > On Tue, 28 Jul 2009, Prateek Agarwal wrote: >> Chris Dempsey wrote: >>> I think you're looking for: >>> >>> 2 ** 3 => 8 >> >> Thanks Chris. >> The following code is showing some error. Can you tell me what the >> problem is? >> >> def power(a,b) >> result=a**b >> result.to_i > > This does not change result. However, if you leave off the next line, it > might behave as you're desiring, provided you've passed in numbers (and not > strings, see below) > >> return result >> end >> >> puts "a=" >> a=gets > > This returns a string > >> a.to_i > > This evaluates as an integer, but doesn't change a It _cannot_ convert objects class. "a.to_i" may return an integer but there is no "a.to_i!" that makes a Fixnum out of a String object. "a.class" remains "String". I don't like the to_i method very much because it just returns zero for wrong input. In most cases I prefer the Integer function. Integer "123" # => 123 Integer "010" # => 8 Integer "0x10" # => 16 Integer "xxx" # raises an ArgumentError "0x10".to_i # => 0 "xxx".to_i # => 0 Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de