Looking for a simple source of ruby code or example program that print declared variables online? Well, this post will help you. You may try this on your ruby code editor.
#!/usr/bin/ruby
class Person
attr_accessor :name, :age, :height, :weight
def full_info
return "#{@name} is #{@age} years old, his/her height is #{@height} and weight is #{@weight}"
end
end
fred = Person.new
fred.name = "Kevin"
fred.age = 21
fred.height = "5'8"
fred.weight = "55 kilos"
puts fred.full_info
save file as sample.rb then execute it, how to execute? just type ruby sample.rb on terminal then enter.
Output:
More ruby coding jobs to come, if you want to request more or question to ask, please free to comment below.
No comments:
Post a Comment