“Ruby -Klasse -Variable” Code-Antworten

Ruby -Klasse -Variable

class Customer
   @@no_of_customers = 0
end
Clumsy Caterpillar

Rubinklasse

class Dog # Initialize class!
    def initialize(name) # Initialize function of class Dog
        @name = name # Set name to param in class
    end

    def print_name() # Function to print out the name in params
        puts @name # Puts!
    end
end

my_dog = Dog.new "Bruno" # Create class and save it in variable
my_dog.print_name # Call print_name function from class

# Output:
# Bruno
Solindek

Ähnliche Antworten wie “Ruby -Klasse -Variable”

Fragen ähnlich wie “Ruby -Klasse -Variable”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen