Skip to content

Ruby class:Day 4

21/12/2010

This day i started with method(function),class and object.

   i learn how to derive a class,methods and create object.

   types of variable -> local ,global, instance and class variable
  class Sample
  attr_reader:first_value
  attr_writer:second_value
  def initialize(first_value,second_value)
    @first_value=first_value
    @second_value=second_value
  end
  def mycall
    total=@first_value+@second_value
  end
end
call=Sample.new(20,40)
print call.mycall
call.second_value=30
print call.mycall
  

==> @instance="value" - instance variable can access from all method. There are three types of oops concept 1.Data Encapsulation 2.Polymorphism 3.Inheritance ==> attr function used to access the local variable in out of class. attr_reader —> getter method attr_writer —-> putter method ==> "shanmugam".object_id -- it change :shanmugam.object_id -- it is a symbol cont change object id ==> include? - this function used to check weather is it or not Ex: irb(main):009:0> "welcome".split('').include?'c' => true

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: