Monday, September 3, 2018

Simple ruby program source code

  Kevin Cosme       Monday, September 3, 2018
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.
logoblog

Thanks for reading Simple ruby program source code

Previous
« Prev Post

No comments:

Post a Comment