Archive for March 6th, 2008

Ruby : $ Symbols

Posted on March 6, 2008. Filed under: Uncategorized |

global_variables: all the global variables in ruby.
$: , $LOADPATH –> gives the path where ruby would be checking if the file is present.
$_ –> where chop will chop/chomp will cut the last character / passed parameter.
$STDOUT,$STDERR,$STDIN –> 3 stream which are created as global parameter(instantiated for you already .these are instance of IO classes).
$0 –> [...]

Read Full Post | Make a Comment ( None so far )

Ruby – Object

Posted on March 6, 2008. Filed under: Uncategorized |

Object is a super super class from which all classes inherit even if there was no inheritance.you can check this by getting the ancestors of the your object .3.ancestors would give Object as the first class followed by others and modules. Object has several other intersting methods/ Things that can be done on any object [...]

Read Full Post | Make a Comment ( None so far )

Ruby :String

Posted on March 6, 2008. Filed under: Uncategorized |

As with Any Class with Ruby the way to create a new instance of the class would be thename.new.so for String as well we can create a new String using a = String.new. a.class would give the “String”.Another way/normal way to create string is to assign something between double quote.You can also use single quote. [...]

Read Full Post | Make a Comment ( None so far )

Ruby : Eval , MetaProgramming, Misc

Posted on March 6, 2008. Filed under: Uncategorized |

eval : evaluates a string as if it was code…
when create a class you open up a new scope …class Foo self is local variable in the scope end.
class_eval opens up the class..for adding methods to it…also this doesn’t start a new local scope….so all the global variables are available….basically what ever string/code is there [...]

Read Full Post | Make a Comment ( None so far )

Ruby : Conditional

Posted on March 6, 2008. Filed under: Uncategorized |

use normal ‘or’ instead of || , ‘and’ instead of &&
range operators; Range.new(1,9)/=== works for comparision/
——————————————————————————————————-
p “hello” if true or use if true then statement end.(if on the same line)
——————————————————————————————————-
if true
end
——————————————————————————————————-
if true
else
end
——————————————————————————————————-
if true
elsif
end
——————————————————————————————————-
unless i_say_no (opposite of if)
do whatever
else
end
——————————————————————————————————-
tertiary/assignment operator
label = condition ? argument1 : argument2
if condition is true then argument1 will passed to label else [...]

Read Full Post | Make a Comment ( None so far )

Ruby : Classes, Object, Inheritance, Module , Mixin

Posted on March 6, 2008. Filed under: Uncategorized |

Class name starts with a capitabl letter.And class definition itself is a object of the Class class.Instance Variable for a class starts with @.And class variable starts with @@. to set it you can user attr,attr_reader,attr_writer,attr_accessor followed by :field-name.
Class method start with class name .whereas the object/instance methods are defined with a small letter.
There are [...]

Read Full Post | Make a Comment ( None so far )

Ruby : Hash

Posted on March 6, 2008. Filed under: Uncategorized |

Hash is the key/value pair.Just like any other class new instance can be created by Hash.new. h.class give “Hash”. and intialize by passing it with parameter Hash.new “init”. Use the normal way { 1 => “jan” , 2 => “feb” }.
zip.keys, zip.values, zip.has_key?(1), zip.has_value?, zip.values_at, z.index , z.select |find_all
zip.each/zip.each_key/zip.each_value
change/ assign values just like array –> [...]

Read Full Post | Make a Comment ( None so far )

Ruby: Arrays

Posted on March 6, 2008. Filed under: Uncategorized |

Just like any other class the way to create this is Array.new. a.class would give the name as “Array”.and a.empty? would tell if it is empty or not . .new 12 would create an array with 12 element , you can initialize these elements by passing another parameter a(9,”hello”) .a.clear will clear the array(empty the [...]

Read Full Post | Make a Comment ( None so far )

Ruby: File/IO

Posted on March 6, 2008. Filed under: Uncategorized |

The 2 most important classes for File IO are File and Dir .This has a lot of class methods which can be accessed as File:: or File.method_name.There is another class calle FileUtil which also has a lot of useful methods.2 most important global variable you must know when using File/Dir is ARGV / ARGF .ARGV [...]

Read Full Post | Make a Comment ( None so far )

Ruby – Gem

Posted on March 6, 2008. Filed under: Uncategorized |

Ruby Gems:
gem –help
gem install “name of the gem ” .This can found from netbeans -> tools -> gems -> newgems…
gem uninstall gemname
gem dep rails
gem env
gem env gemdir
gem list –local
gem list –remote
gem list rails –remote

Read Full Post | Make a Comment ( None so far )

« Previous Entries
  •  

    March 2008
    M T W T F S S
    « Feb   Apr »
     12
    3456789
    10111213141516
    17181920212223
    24252627282930
    31  
  • My Fav

Liked it here?
Why not try sites on the blogroll...