Skip to content

Instantly share code, notes, and snippets.

View x0bandeira's full-sized avatar

Rafael Bandeira x0bandeira

View GitHub Profile
tradução
--------
Tem conhecimentos que conhecemos. São as coisas que nós sabemos que sabemos.
Tem conhecimentos que não conhecemos. Isso é, tem coisas que nós sabemos que não sabemos.
Mas tem também conhecimentos desconhecidos. Essas são as coisas que não sabemos que não sabemos.
original
--------
There are known knowns. These are things we know that we know.
class MyClass
attr :name #this will create a getter for this property
attr :hair_color, true #the _true_ parameter will enable a setter for this property
end
class MyClass
attr :name #this will create a getter for this property
attr_accessor :hair_color #this will create a getter and setter for this property
end
class MyClass
attr :name #this will create a getter for this property
attr_accessor :hair_color #this will create a getter and setter for this property
attr_reader :age, :surname, :birthdate #this will create only getters for all these properties
attr_writer :listening, :talking #this will create only setters for all these properties
end
class MyClass
def complex_property
@my_complex_property
end
def complex_property= value
#complex logic
@my_complex_property = revamped_value
end
$ sudo gem install rack-test
$ touch test.rb
$ echo "require 'rack/test'" >> test.rb
$ ruby test.rb
$ gem which rack
/var/lib/gems/1.9.1/gems/rack-1.2.1/lib/rack.rb
$ gem which rack/test
/usr/lib/ruby/gems/1.9.1/gems/rack-test-0.5.4/lib/rack/test.rb
$ sudo ln -s /usr/lib/ruby/gems/1.9.1/gems/rack-test-0.5.4/ /var/lib/gems/1.9.1/gems/
##
# odd difference between Ruby's AND comparison operators: '&&' and 'and'
##
# with '&&' it will throw an error expecting 'end' after params.include?
if request.post? && request.params.include? 'post_param' then
end
# with 'and' it will work fine and you'll call the day for a beer
if request.post? and request.params.include? 'post_param' then