Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

Ruby | Class & Object

# Ruby program to illustrate the passing
# parameters to new method
 
#!/usr/bin/ruby
 
# defining class Vehicle
class Vehicle
 
# initialize method
def initialize(id, color, name)
 
# variables
@veh_id = id
@veh_color = color
@veh_name = name
 
# displaying values
puts "ID is: #@veh_id"
puts "Color is: #@veh_color"
puts "Name is: #@veh_name"
puts "
"
end
end
 
# Creating objects and passing parameters
# to new method
xveh = Vehicle. new("1", "Red", "ABC")
yveh = Vehicle. new("2", "Black", "XYZ")
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #Ruby #Class #Object
ADD COMMENT
Topic
Name
5+8 =