Tuesday, June 27, 2006

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.


At 2:38 pm, Blogger raj said...

"And how are dates stored?"
Hi Ashish, Raj here. Here is your doubt that cheered me while answering.
below is the code for printing date:
require 'date'

#d = Date.new(2000, 3, 31)
d = Date.today()
puts d
#To print time:

puts Time.at(0)
#here in bracket you can set the seconds with time. just put some random number n try to analyze output.

At 9:19 pm, Blogger Ashish Kulkarni said...

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.



At 12:42 am, Blogger SatishTalim said...

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!

At 9:07 am, Blogger raj said...

require 'date'

just put the above preprocessor. But in my system, it has worked without including the above one.
Nyway try this complete code

require 'date'
d1 = Date.today()
puts d1

At 12:51 am, Blogger Ari said...

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