Skip to content

Instantly share code, notes, and snippets.

@nmelox
Created May 6, 2011 18:22
Show Gist options
  • Save nmelox/959483 to your computer and use it in GitHub Desktop.
Save nmelox/959483 to your computer and use it in GitHub Desktop.
primer proyect ruby NM
#!/usr/bin/env ruby
Class Perro
attr_accessor :nombre
attr_accessor :edad
def initialize(nombre="Mundo",edad="0")
@nombre=nombre
@edad=edad
end
def ladrar
if @nombre.nil?
puts "#{@nombre} (Edad"#{@edad}): warf warf!!!"
elseif @nombre.respond_to?(each)
@nombre.each do |nombre|
puts "#{@nombre} (Edad"#{@edad}): warf warf!!!"
end
else
puts "#{@nombre} (Edad"#{@edad}): warf warf!!!"
end
end
end
if _FILE_ ==$0
p=Perro.new
p.ladrar
p.nombre="Manu"
p.ladrar
p.nombre=["Frodo","Jack","Terry"]
p.ladrar
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment