Skip to main content
Hide Sidebar
Show Sidebar
<Progzoo Sections>
ProgZoo
Tutorials
How to...
Assessments
Help
<Other>
To do list
Recent changes
Progress
Random page
Personal
Log in / create account
Views
Ruby
Discussion
View source
History
Toolbox
What links here
Related changes
Special pages
Printable version
Tutorials
SET07102
Guides
Log in
Java
C#
C++
Perl
PHP
Python
Ruby
VB
Ruby:Define a Class
From Progzoo
Ruby:Top Ten Tips
Hello World
Convert to Number
Read Text File
Sum an Array
Count 0 to 9
Hash Table
Regular Expression
Read Database
Read XML
Define a Class
The class Person has
a constructor:
Person
attributes
n, w
and
h
a method:
bmi
.
class Person attr_accessor :n, :w, :h def initialize(name,weight,height) @n=name @w=weight @h=height end def bmi() return w/h/h end end p = Person.new("andrew",95,1.8) puts p.bmi() puts p.n
[
Font
] [
Default
] [
Show
] [
Resize
] [
History
] [
Profile
]
test text