Braindump / Ch 2 Beginning Ruby

June 20, 2008 @ 11:55 PM | posted by carmelyne

(last updated: 06.21.08)

CH 2: TOUR OF RUBY & OBJECT ORIENTATION


Object

  1. an object is a single instance of a class.
  2. object is the actual object or “thing” itself.
  3. an object of class Person is a single person

Classes

  1. a class is the classification
  2. the definition of a single type of object
  3. starts with a capital letter just like global constants which therefore makes it available as a global constant.

attr in attr_accessor

  1. stands for “attribute”

accessor in attr_accessor

  1. roughly means “make these attributes accessible to be set and changed.”

Inheritance like Single Table Inheritance

  1. hierarchy of classes; and sub/child classes inherits attributes and methods from the parent class
  2. can still add class-specific code to sub/child class

Class Method

  1. ruby supplies all objects a class by default
  2. you can ask any object of which class it’s a member by using its class method, i.e. puts 2.class

Fixnum Class

  1. numbers

Kernel & Kernel Methods

  1. kernel is a special class(actually, a module) whose methods are made available in every class and scope throughout ruby.

puts

  1. is a method made available from the Kernel module

Kernel module

  1. a special type of class packed full of standard, commonly used methods, making your code easier to read and write

String Class

  1. strings
  2. has many methods, examples: capitalize, downcase, chop, hash, next, reverse, sum, or swapcase.

Braindumps from Beginning Ruby

[ Last updated: June 21, 2008 @ 12:34 AM ]

Sorry, comments are closed for this article.

Snippets of 06/24/07

Rails 'A'..'Z' Paginate

1
2
3
4
5
6
7
8
9
10
11
# Starts with 'A'..'Z' Paginate / model
def self.sort(sort)
  if sort
    find(:all, :conditions => ['name LIKE ?', "#{sort}%"])
  else
    find(:all, :order => 'name')
  end  
end

# index action / controller
@models = Model.sort(params[:sort]) 

Recent Posts...

RailsConf 2006
I heart devChix