This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Person = Class.new do | |
| #instance method | |
| def say_hi | |
| puts "Hi, Do you like Ruby?" | |
| end | |
| end | |
| Person.new.say_hi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module A | |
| def say_hi(a,b,c) | |
| puts "Hi, from [A] module. Numbers - #{a} #{b} #{c}" | |
| end | |
| end | |
| class B | |
| include A | |
| def say_hi(a,b,c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module A | |
| def say_hi(a,b,c) | |
| puts "Hi, from [A] module. Numbers - #{a} #{b} #{c}" | |
| end | |
| end | |
| class B | |
| include A | |
| def say_hi(a,b,c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module A | |
| def say_hi(a,b,c) | |
| puts "Hi, from [A] module. Numbers - #{a} #{b} #{c}" | |
| end | |
| end | |
| class B | |
| include A | |
| def say_hi(a,b,c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module A | |
| def say_hi(a,b,c) | |
| puts "Hi, from [A] module. Numbers - #{a} #{b} #{c}" | |
| end | |
| end | |
| class B | |
| include A | |
| def say_hi(a,b,c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person | |
| def say_hi | |
| puts "Hi, this is Ruby!" | |
| end | |
| end | |
| john = Person.new | |
| robin = Person.new | |
| john.say_hi # => Hi, this is Ruby! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyClass | |
| def my_instance_method | |
| puts "this is an instance method" | |
| end | |
| #self here is MyClass | |
| class << self | |
| def count_objects | |
| "counting objects..DONE" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ bundle install | |
| Fetching source index for http://rubygems.org/ | |
| Installing rake (0.9.2) | |
| Installing abstract (1.0.0) | |
| Installing activesupport (3.0.5) | |
| Installing builder (2.1.2) | |
| Installing i18n (0.6.0) | |
| Installing activemodel (3.0.5) | |
| Installing erubis (2.6.6) | |
| Installing rack (1.2.3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ruby-1.9.2-p180 :001 > Account.find(34) | |
| ActiveRecord::RecordNotFound: Couldn't find Account with ID=34 | |
| from /Users/lakshman/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.5/lib/active_record/relation/finder_methods.rb:296:in `find_one' | |
| from /Users/lakshman/.rvm/gems/ruby-1.9.2-p180/gems/activerecord- | |
| ruby-1.9.2-p180 :002 > Account.where(:id => 34).first | |
| => nil | |
| ruby-1.9.2-p180 :003 > Account.where(:id => 34) | |
| => [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def my_awesome_method | |
| ret = lambda { return "This is returned from Lambda" } | |
| ret.call | |
| "This line will run" | |
| end | |
| puts my_awesome_method | |
| # => "This is returned from Lambda" | |
| # => "This line will run" |