Online Ruby Formatter

Help Tutorials Coding Ground View Edit Dev Tools
Online Image Optimizer
Online LaTex Editor
LaTex Equation Editor
Whiteboard
Online Image Editor
Online XML Editor
Online JSON Editor
File Conversion
More Tools...
Undo
Redo
Cut
Copy
Paste
Delete
Select All
Find
Find and Replace
Editor Theme
Chrome
Crimson Editor
Dreamweaver
Eclipse
Github
Kuroir
Solarized Light
Solarized Dark
XCode
Ambiance
Cobalt
idle Fingers
krTheme
Mono Industrial
Monokai
Terminal
Textmate
Tomorrow
Twilight
Vibrant Ink
Font Size
8px
9px
10px
11px
12px
13px
14px
15px
16px
17px
18px
20px
22px
24px
Tab Size
1
2
3
4
5
6
7
8
Soft Wrap
On
Off
40 Chars
60 Chars
80 Chars
100 Chars
120 Chars
140 Chars
Show Invisible
Hide Invisible
Show Gutter
Hide Gutter
Download
#!/usr/bin/ruby -w

# define a class
class Box
# constructor method
def initialize(w,h)
@width, @height = w, h
end

# accessor methods
def getWidth
@width
end
def getHeight
@height
end

# setter methods
def setWidth=(value)
@width = value
end
def setHeight=(value)
@height = value
end
end

# create an object
box = Box.new(10, 20)

# use setter methods
box.setWidth = 30
box.setHeight = 50

# use accessor methods
x = box.getWidth()
y = box.getHeight()

puts "Width of the box is : #{x}"
puts "Height of the box is : #{y}"
© Copyright 2023. All Rights Reserved.
Beautify | upload files Upload File