Ruby class/Module name must be constant error

Source: Internet
Author: User

Ruby error prompt:

Class/Module name must be constant

= Begin to comment

This is also comment
= End

Puts "nolonggercomments ";

# Rdoc rules
# = Headers
# This is header content
#== Sub Headers
# This is sub header content
#=== Sub Headers
# This is sub Headers
Class animal
# This is the comment for the 'new' method!
Def initialize type
@ Name = Type
End
 
# This is comment for 'shout' Method
# Second line
# * This is sub line 1
# * This is sub Line 2
 
Def shout
If @ name = 'Dog'
Puts "Wang! Wang! "
Elsif @ name = 'cat'
Puts "Miao! Miao! "
End
End
 
End

Dog = animal. New 'dog'
Dog. Shout

Gets

Ruby class names must be capitalized.

This involves a convention on Ruby interpreters.

::

1. Set the variables encoded in acsii and whose names start with uppercase as Constants by default.

2. The first letter of a local variable in ruby is in lower case.

3. the constructor name in ruby is initialize.

4. The leading @ character of the member variable (instance variable) in ruby, which is declared and initialized in initialize.
5. attributes in ruby are declared using attr_writer and attr_reader, which correspond to the set and get of C # respectively. attr_accessor is readable and writable.
6. The $ operator of the global variable in ruby.
7. constants (constants) in Ruby start with uppercase letters, and the conventions are all uppercase letters.

Solution:

Change the class name to animal.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.