Class: Alimento::Alimento
- Inherits:
-
Object
- Object
- Alimento::Alimento
- Includes:
- Comparable
- Defined in:
- lib/alimento.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#gluc ⇒ Object
readonly
Returns the value of attribute gluc.
-
#lip ⇒ Object
readonly
Returns the value of attribute lip.
-
#nombre ⇒ Object
readonly
Returns the value of attribute nombre.
-
#prt ⇒ Object
readonly
Returns the value of attribute prt.
Instance Method Summary collapse
- #<=>(another) ⇒ Object
-
#initialize(nombre, prt, gluc, lip) ⇒ Alimento
constructor
A new instance of Alimento.
- #kcal ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(nombre, prt, gluc, lip) ⇒ Alimento
Returns a new instance of Alimento.
16 17 18 19 20 21 |
# File 'lib/alimento.rb', line 16 def initialize(nombre,prt,gluc,lip) @nombre=nombre @prt=prt @gluc=gluc @lip=lip end |
Instance Attribute Details
#gluc ⇒ Object (readonly)
Returns the value of attribute gluc.
9 10 11 |
# File 'lib/alimento.rb', line 9 def gluc @gluc end |
#lip ⇒ Object (readonly)
Returns the value of attribute lip.
9 10 11 |
# File 'lib/alimento.rb', line 9 def lip @lip end |
#nombre ⇒ Object (readonly)
Returns the value of attribute nombre.
9 10 11 |
# File 'lib/alimento.rb', line 9 def nombre @nombre end |
#prt ⇒ Object (readonly)
Returns the value of attribute prt.
9 10 11 |
# File 'lib/alimento.rb', line 9 def prt @prt end |
Instance Method Details
#<=>(another) ⇒ Object
12 13 14 |
# File 'lib/alimento.rb', line 12 def <=>(another) kcal <=> another.kcal end |
#kcal ⇒ Object
27 28 29 |
# File 'lib/alimento.rb', line 27 def kcal() @prt*4+@gluc*4+@lip*9 end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/alimento.rb', line 23 def to_s() "#{@nombre} prt=#{@prt}g gluc=#{@gluc}g lip=#{@lip}g" end |