This file contains 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
How to declare a method: | |
- (returntype)nameofTheMethodParam:(paramtype)paramname andAnotherParam:(paramtype)paramname; | |
+ (returntype)nameofTheMethodParam:(paramtype)paramname andAnotherParam:(paramtype)paramname; | |
Not like these: | |
-(returntype)nameofTheMethodParam:(paramtype)paramname andAnotherParam:(paramtype)paramname; | |
-(returntype) nameofTheMethodParam:(paramtype)paramname andAnotherParam:(paramtype)paramname; |
This file contains 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
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] |
This file contains 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
irb(main):007:0> class Person | |
irb(main):008:1> attr_accessor :name,:email | |
irb(main):009:1> end | |
=> nil | |
irb(main):010:0> p = Person.new | |
=> #<Person:0x007fa40a038378> | |
irb(main):011:0> p.name | |
=> nil | |
irb(main):012:0> p.email | |
=> nil |
This file contains 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
#all these will render guests/new.html.erb template | |
#calling from an action in ActivitiesConctoller, for example. | |
render "guests/new" | |
render "guests/new.html.erb" | |
render :template => "guests/new" | |
render :template => "guests/new.html.erb" |
This file contains 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
# SeniorDev, AwesomeDev, NoviceDev | |
class SeniorDev | |
def do_some_old_stuff | |
puts "This is a piece of cake" | |
end | |
def method_missing(name, *args) | |
puts "Err.. What? #{name}??.. THAT IS IMPOSSIBLE! Leave me alone." | |
end |
This file contains 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
my_super_code = lambda { |a,b| return a+b; } | |
puts my_super_code.call(1,2,5) | |
#=> ArgumentError: wrong number of arguments (3 for 2) |
This file contains 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" |
This file contains 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 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 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" |