jnunemaker/twitter — comment on commit 6fb7b3fffdb953e07348e87f6a3af23f603e996f
File: lib/twitter/configuration.rb line 15
By dkubb:

If you benchmark this I bet you'll find that most of your time in `#initialize` now is because you're eagerly setting all the ivars, even if they never get used. What I would suggest is moving them out into accessors, eg:

```ruby
def photo_sizes
return @photo_sizes if defined?(@photo_sizes)
@photo_sizes = @attributes['photo_sizes'].each_with_object({}) do |(key, value), object|
object[key] = Twitter::Size.new(value)
end
end
```

or even better:

```ruby
def photo_sizes
@photo_sizes ||= Array(@attributes['photo_sizes']).each_with_object({}) do |(key, value), object|
object[key] = Twitter::Size.new(value)
end
end
```