Created
July 18, 2011 23:10
-
-
Save prodis/1090921 to your computer and use it in GitHub Desktop.
Ruby Fundamental - Hash em Ruby (parte I)
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
| even_numbers = {} # Cria um objeto hash vazio | |
| even_numbers["zero"] = 0 # Atribui 0 como valor para a chave "zero" | |
| even_numbers["two"] = 2 | |
| even_numbers["four"] = 4 | |
| even_numbers["two"] # Recupera 2 como valor |
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
| even_numbers = {} | |
| even_numbers[:zero] = 0 | |
| even_numbers[:two] = 2 | |
| even_numbers[:four] = 4 |
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
| even_numbers = { :zero => 0, :two => 2, :four => 4 } |
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
| even_numbers = { zero: 0, two: 2, four: 4 } |
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
| misc_hash = { | |
| :string => "Some text", | |
| :number => 456, | |
| :boolean => false, | |
| :array => [0, 1, 2] | |
| } |
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
| even_numbers = { :zero => 0, :two => 2, :four => 4 } | |
| even_number.each do |key, value| | |
| print "|#{key}: #{value}| " | |
| end | |
| # Imprime "|zero: 0| |two: 2| |four: 4| " |
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
| even_numbers = { :zero => 0, :two => 2, :four => 4 } | |
| even_number.each_key { |key| print "#{key} " } | |
| # Imprime "zero two four " | |
| even_number.each_value { |value| print "#{value} " } | |
| # Imprime "0 2 4 " |
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 OrdersController < ApplicationController | |
| def payment | |
| @order = Order.find_by_number params[:id] | |
| @payment_method = PaymentMethod.find params[:payment_method_id] | |
| # Alguma implementação | |
| end | |
| # Mais ações | |
| end |
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 ShippingCalculator | |
| def calculate(weight, height, width, depth) | |
| # Alguma implementação | |
| end | |
| end |
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 ShippingCalculator | |
| def calculate(weight, dimensions = {}) | |
| # Alguma implementação | |
| end | |
| end | |
| dimensions = { :height => 0.75, :width => 1.00, :depth => 0.10 } | |
| calc = ShippingCalculator.new | |
| calc.calculate 1.50, dimensions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment