Files
dockerfiles/tests/ruby/testcase/variablescope.rb
2019-08-04 22:54:34 -07:00

29 lines
602 B
Ruby

class Computer
$manufacturer = "Apple Computer, Inc."
@@files = {hello: "Hello, world!"}
def initialize(username, password)
@username = username
@password = password
end
def current_user
@username
end
def self.display_files
@@files
end
end
# Make a new Computer instance:
hal = Computer.new("Dave", 12345)
puts "Current user: #{hal.current_user}"
# @username belongs to the hal instance.
puts "Manufacturer: #{$manufacturer}"
# $manufacturer is global! We can get it directly.
puts "Files: #{Computer.display_files}"
# @@files belongs to the Computer class.