This page contains automated test results for code from O'Reilly's Ruby Cookbook. If this code looks interesting or useful, you might want to buy the whole book.
| Defining a Virtual Attribute | ||
|---|---|---|
| Code | Expected | Actual |
class Arc
attr_accessor :radians
def degrees
@radians * 180 / Math::PI
end
def degrees=(degrees)
@radians = degrees * Math::PI / 180
end
end
arc = Arc.new
arc.degrees = 180
arc.radians |
3.14159265358979 | 3.14159265358979 |
arc.radians = Math::PI / 2 arc.degrees |
90.0 | 90.0 |