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

> puts "b="
> b=gets

This returns a string

> b.to_i

this returns an integer but doesn't change b

> c=power(a,b)

you're passing in two strings here.....  You'll get an error like:

NoMethodError: undefined method `**' for "1\n":String


> puts "c=#{c}"
>

Matt