In my gem I have a class called Client
that I want to operate like this:
client = Client.new
client.content_type('pages').content_type
That means I want to set a property and then expect to immediately get it back in the same chain. This is what I have so far:
class Client
attr_reader :content_type
def initialize(options = {})
@options = options
end
def content_type
@content_type
end
def content_type(type_id)
@content_type = type_id
self
end
end
Now when I try to run client.content_type('pages').content_type
I get:
wrong number of arguments (given 0, expected 1) (ArgumentError)
from chaining.rb:16:in `<main>'
What am I doing wrong? How do I write this correctly?