Link to home
Start Free TrialLog in
Avatar of neophyteScripter
neophyteScripter

asked on

Create a Class based on an Object

As the name suggests, I am new to scripting in general and have my primary education in HTML and CSS. I'm just looking for a simple example of a Class that pulls in data from an Object.

Here is the base of what I am working on. Very simplistic

# NewDeviceClass

class NewDevice
    attr_accessor :device_names
    #Create the object
  def initialize(device_names = "Mobile Device Alpha")
    @device_names = device_names

  end

  #display nickname of device
def nickname
  if @device_names.nil?
    puts "..."
  elsif @device_names.respond_to?("each")

    @device_names.each do |device_names|
      puts "Device Nickname #{device_names}"
    end
  else
    puts "Hello #{@device_names}!"
  end
end

#End Tag
end


if __FILE__ == $0
dn = NewDevice.new
dn.nickname


#List of Device Names
dn.device_names = ["windows_pc", "apple_iphone", "android", "ubuntu", "symbian"]
dn.nickname

end


I know that I created the object here, but what if I wanted to be able to pull information from an existing object?

Any help is appreciated... FYI I am using NetBeans and running the files via Terminal on Mac OSX
ASKER CERTIFIED SOLUTION
Avatar of kristinalim
kristinalim
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of neophyteScripter
neophyteScripter

ASKER

Close enough. I think I have it now, thanks