Skip to content

Elements of Computing Systems Chapter 11c

Tom Stuart edited this page Jul 8, 2015 · 17 revisions

Exercises

Asides

  • When first implementing the Number class, we tried using a Struct with no values but this raises an ArgumentError. Tom mentioned that he'd hit this problem in his book but that someone had written to tell him that it is possible to create "nullary" Structs by passing nil instead:
> Struct.new
ArgumentError: wrong number of arguments (0 for 1+)
> Struct.new(nil)
=> #<Class:0xdecafbad>
1.upto(10).each do |i|
  puts i if (i == 2) .. (i == 6)
end
#=> 2
#=> 3
#=> 4
#=> 5
#=> 6
Clone this wiki locally