Hi, Pawell

> I got exception saying I try to call gsub on null. Now this is strange...

First, let's do something very simple in irb:

x = x + 1

Do you see what happened? you are trying to assign a value to a variable
that you just created (on the left side) which is for the moment nil, so ...
does it make sense?

And this is exactly what happens when you wrote.
   name = name.gsub...
Do you see it now? (if not, don't be afraid to ask again; I am sure that
your questions are shared by many).

> If you could also explain how ruby can think "name" on the left side is
method. It has "=" sign on the right, is it possible with methods?

Ah... but the method would be not 'name' but '*name=*'. In the code that we
discussed, Ruby has to decide if you are creating a local variable 'name' or
calling the accessor *name=* (that for the reasons discussed you should
write '*self.name=*').

Do you see it now?

> It's not new programming language. It's new way of thinking...

Everyone thinks that just by writing the Rails code, they are going to learn
Ruby. They will not.

You have a young and inquisitive mind (shown by the questions that you ask
yourself); do not learn just Rails; take a real book about Ruby, like *The
Programming Language Ruby* (written by D.Flanagan and Matz) and read it.
Even if you can just do a few pages per day!

In it, David and Matz say (page 19): ...*it is easy to program in Ruby, but
Ruby is not a simple language.*

So, from now on, do not believe the people who only mention the first part
of that sentence.
-----

It is always a pleasure to hear your questions (they force me to think,
before answering). Do not hesitate if you have more,

Raul


On Thu, Sep 25, 2008 at 5:01 AM, Paweł Stawicki <[EMAIL PROTECTED]>wrote:

>
> Thanks for your answer. As usually, things are clearer, but more
> questions arise.
>
> When I removed "self", leaving just
>
> name = name.gsub(/[^A-Za-z]/, "") if attribute_present?("name")
>
> I got exception saying I try to call gsub on null. Now this is strange...
>
> If you could also explain how ruby can think "name" on the left side
> is method. It has "=" sign on the right, is it possible with methods?
>
> I come from java (and earlier C++) world, and I can see in ruby many
> things are sooo different. It's not new programming language. It's new
> way of thinking. That's why I wanna learn it.
>
> Best regards
> --
> Pawel Stawicki
> http://pawelstawicki.blogspot.com
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "ruby-on-rails-programming-with-passion" group.
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/ruby-on-rails-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to