Comments in Ruby!!!
Just finished the next few Ruby programs. What did I learn? Well, the first thing is COMMENTS!!!
Single line comments start with #. Put a # anywhere on the line and rest of the line becomes a comment.
Multiline comments start with =begin and end with =end.
It must be noted that /*, */ and // do not work.
Just tried the oracle way and no, -- does not work either.
Semi-colons, whether at the beginning or at the end of the, statement are ignored as well.
I hate to say this but Ruby is a completely new language. So woe is me. No shortcuts. I will have to learn everything from scratch.
And I thought that they were joking when they said life begins at 30 (in my case, 34).
No, I don't feel like Alice in wonderland or Dorothy following the yellow brick road.
I still have more questions.
Yes, I do want to know as to why people start new languages rather than adding to existing ones. But we won't go there yet.
Now that we can output stuff, my next question is how do we read stuff from console into variables?
And how do we format the output?
And how are dates stored?
Again, I am sure, all will be revealed in good time.
Kate wants to know who this Ruby is that I am spending half an hour with everyday.
3 Comments:
Hi Raj,
Thanks for your reply. I tried the Date program as follows:
d = Date.today()
puts d
This gives me the following error:
>ruby DT.rb
DT.rb:1: undefined method `today' for Date:Class (NoMethodError)
>Exit code: 1
Any ideas?
Good to know that there is a Date class though. It will come handy.
Regards,
Ashish.
Good to see you guys exploring Ruby. Better warn Kate that the new girl-friend Ruby is very demanding!! Finally, life begins at 51 for me!
Your problem is that you haven't created a new instance of the class - remember, Ruby is object-oriented.
d = Date.new.today
puts d
you need the new, because otherwise the object doesn't actually exist.
Post a Comment
<< Home