Skip to content

Ruby Class:Day 7

29/12/2010

This day start with preparation of calendar for 2011.

Before that try simple multiplication table task

#Multiplication table

ranges = [1..6,7..12]
table_upto = [1..12]
ranges.each do |range|
  for table in 1..12 do
    range.each_with_index do |number,index|
      print "%2d"%table+" X "+"%2d"%number+" = "+ "%3d "%(number*table)
      print "   "
    end
    puts
  end
  puts
end
==>From this program i learn how to display the  value of variable inside the cots(" ") 
         by using --  #{variable_name}             
 
==>Assign the display occupation size length of the variable.
          "%3d"%(variable_name)

      Then from base of this concept start to prepare calendar for 2011.
      before code learn some basic time function

==> Time.now() --Return current time.
       Ex:
         irb(main):008:0> Time.now()
         => Wed Jan 05 22:42:45 +0530 2011
==>Time.local() -- it will return day easy identify the which day the month start.
       Ex:
          irb(main):016:0> Time.local(2010,12)
          => Wed Dec 01 00:00:00 +0530 2010
==>strftime()  -- use for fetching individual value like year,day,month...

      Ex:
        irb(main):019:0> t.strftime('%a')
        => "Wed"
        irb(main):020:0> t.strftime('%B')
        => "January"
   for more about time http://www.ruby-doc.org/core/classes/Time.html
 
Advertisements

From → Ruby

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: