Skip to content

Instantly share code, notes, and snippets.

@rodrigomanhaes
Created October 17, 2011 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodrigomanhaes/1293392 to your computer and use it in GitHub Desktop.
Save rodrigomanhaes/1293392 to your computer and use it in GitHub Desktop.
map, to_proc, Symbol, etc...
def total
soma = 0
itens_orcamento.each {|item| soma += item.total }
soma
end
def total
itens_orcamento.map {|item| item.total }.sum
end
.to_proc
class Symbol
def to_proc
lambda {|x| x.send(self) }
end
end
def total
itens_orcamento.map(&:total).sum
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment