notahat/machinist — pull request #118 by jamesottaway (2012-08-01 23:56:48+00:00)
Title: Build immutable classes

Immutable classes are my friend, but machinist doesn't seem to like them. This patch fixes that.

The `Lathe` class has traditionally called the `#{key}=` method on the object in question to set a given value, but my immutable friends don't have that method.

Because `attr_reader` uses instance variables under the hood, machinist can set the instance variable in question to the given value and all will be happy.

I had to use a `begin` block in `Lathe` because the `OpenStruct` instances used by other specs in `machinable_spec.rb` doesn't support `#respond_to?`. If this was changed the patch could be refactored to use `if @object.respond_to?("#{key}=")`.