Last active
December 18, 2015 17:59
-
-
Save lucasrenan/5822864 to your computer and use it in GitHub Desktop.
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
| # construir um algoritmo que recebe via console a | |
| # idade de uma pessoa e retorna algo como: | |
| # - maior de idade | |
| # - menor de idade | |
| # ps. utilize métodos :) | |
| puts "idade:" | |
| age = gets.chomp | |
| def is_adult?(age) | |
| return true if age.to_i >= 18 | |
| false | |
| end | |
| if is_adult?(age) | |
| puts "maior de idade" | |
| else | |
| puts "menor de idade" | |
| end | |
| # construa um algoritmo que recebe uma lista | |
| # de palavras separadas por virgula. | |
| # no fim, mostre na tela as palavras ordenadas | |
| # alfabeticamente. | |
| puts "palavras separadas por virgula" | |
| words = gets.chomp.split(",") | |
| words.collect!{|w| w.strip} | |
| words.sort! | |
| puts words.join(", ") | |
| #blocos | |
| def learning_blocks(&x) | |
| if block_given? | |
| #x.call("chamando bloco") | |
| yield("chamando bloco") | |
| else | |
| puts "nao tem bloco" | |
| end | |
| end | |
| def sum(num1, num2) | |
| num1.to_i + num2.to_i | |
| end | |
| learning_blocks | |
| learning_blocks do |p| | |
| puts p | |
| puts sum(1, 9) | |
| end | |
| learning_blocks {|p| puts p} | |
| #classes | |
| class Book | |
| attr_accessor :title, :price | |
| def initialize(title, price=0) | |
| @title = title | |
| @price = price | |
| end | |
| end | |
| book = Book.new("ruby", 10) | |
| puts book.class | |
| puts book.title | |
| puts book.price |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment