On Jun 21, 2012, at 12:39 AM, Emeka Patrick wrote:

> x =3D 10
> y =3D 5
>=20
> def square(x)
>  puts "within the method x is " + x.to_s
>  puts x*x
> end

Here, you define method square but do not invoke it yet. 'x' here is a =
method parameter that will take the value provided in a method =
invocation. It does not have anything to do with 'x' in 'x =3D 10'.=20

For example, when you invoke this method as:
  square(25)

x in x.to_s and x*x will be 25. And outer scope x will still be 10 after =
the method returns.

Gennady.

>=20
>=20
> In the above when defining the method, the x that is being referenced =
in
> "x.to_s" and puts x*x is by default the variable x, defined above, =
with
> a value of 10, correct?  This then means that even though this =
variable
> isn't defined within the method it can still be called on from outside
> the code. However, if the variable was given a value within the method
> then it wouldn't be available outside of the method, correct?
>=20
> Can someone explain why this is so. I guess I don't NEED to know why,
> but I'd like to understand it a bit better if possible. Thanks!
>=20
> --=20
> Posted via http://www.ruby-forum.com/.
>=20