Browse files

Update CHANGELOG, improve message.

  • Loading branch information...
1 parent 43ed24e commit 8775ffa37231d381cba34f0ecacb8a7bbcf0573f @josevalim josevalim committed Jun 16, 2011
Showing with 4 additions and 2 deletions.
  1. +3 −1 activesupport/CHANGELOG
  2. +1 −1 activesupport/lib/active_support/memoizable.rb
View
4 activesupport/CHANGELOG
@@ -1,10 +1,12 @@
*Rails 3.2.0 (unreleased)*
+* Deprecated ActiveSupport::Memoizable in favor of Ruby memoization pattern [José Valim]
+
* Added Time#all_day/week/quarter/year as a way of generating ranges (example: Event.where(created_at: Time.now.all_week)) [DHH]
* Added instance_accessor: false as an option to Class#cattr_accessor and friends [DHH]
-* Removed ActiveSupport::SecureRandom in favour of SecureRandom from the standard library [Jon Leighton]
+* Removed ActiveSupport::SecureRandom in favor of SecureRandom from the standard library [Jon Leighton]
@drogus
Ruby on Rails member
drogus added a line comment Dec 20, 2011

Y U NO LIKE BRITISH ENGLISH?! :(

@stevegraham
stevegraham added a line comment Dec 20, 2011

AKA actual English.

@drogus
Ruby on Rails member
drogus added a line comment Dec 20, 2011

:D

@drogus
Ruby on Rails member
drogus added a line comment Dec 20, 2011

I smell a war ;) /cc @jonleighton

@josevalim
Ruby on Rails member
josevalim added a line comment Dec 20, 2011

Aye, I didn't mean to be a pain in the arse. I swear I thought it was a typo. Cheerio.

@drogus
Ruby on Rails member
drogus added a line comment Dec 20, 2011

I thought so, but not picking it up would not be funny :P

@josevalim
Ruby on Rails member
josevalim added a line comment Dec 20, 2011

Bugger off!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
* ActiveSupport::OrderedHash now has different behavior for #each and
#each_pair when given a block accepting its parameters with a splat. [Andrew Radev]
View
2 activesupport/lib/active_support/memoizable.rb
@@ -6,7 +6,7 @@ module ActiveSupport
module Memoizable
def self.extended(base)
ActiveSupport::Deprecation.warn "ActiveSupport::Memoizable is deprecated and will be removed in future releases," \
- "simply use Ruby instead.", caller
+ "simply use Ruby memoization pattern instead.", caller
super
end

15 comments on commit 8775ffa

@tansengming

Just curious, why is this getting deprecated? I just found out about this module today and thought it was a lot cleaner than littering the model with '||='s

@pboling

"simply use Ruby memoization pattern instead."

Memoization is now part of standard Ruby.

@matthewrudy

I'm late to the show.
But curious.

@pboling, what does the ruby memoization look like?
Don't think I've seen anything about it.

@pboling

I should have said that the pattern is now standard, or at least that they consider it standard enough to not need this module.

I have not seen anything defined as the "standard" (by Matz, for example), but in my estimation this would be it:
http://stackoverflow.com/a/963895

def current_user_session
  defined?(@current_user_session) ?
      @current_user_session : @current_user_session = UserSession.find
end
@matthewrudy

I think that's pretty dirty compared to.

def current_user_session
  UserSession.find
end
memoize :current_user_session

and that's a simple example.

def to_params
  to_hash.map do |key, value|
    "#{key}=#{value}"
  end.join("&")
end
memoize :to_params

looks ok.

But....

def to_params
  if defined?(@to_params)
    @to_params
  else
    @to_params = to_hash.map do |key, value|
      "#{key}=#{value}"
    end.join("&")
  end
end

looks gross.

But I guess what we're really saying is that it doesn't belong in Rails.

Think I'll just put it into a memoizable gem.

@josevalim
Ruby on Rails member
def to_params
  @to_params ||= to_hash.map do |key, value|
    "#{key}=#{value}"
  end.join("&")
end

FTFY.

@matthewrudy

I need to think of a more ugly example. :)
Thanks Jose.

@pboling

My original comment was somewhat sarcastic, and that was lost in transmission.

As someone who uses memoize extensively I am dismayed by this change with not so much as a hint as to how to replicate the behavior. It is emphatically NOT the same as ||= and this is a key reason why we switched to memoize. My example does replicate the behavior for our purposes, but swapping that out for our uses of memoize will be nasty. I will install your gem, so please update this thread if you actually do create it!

Also Rails, why didn't you pull this out into a separate plugin/gem like you have with everything else? Not cool.

@josevalim
Ruby on Rails member

Also Rails, why didn't you pull this out into a separate plugin/gem like you have with everything else?

1) Who did most of the extractions previously were Rails developers, not someone from the Rails Core Team;

2) Most plugins extracted from Rails are not even in github.com/rails anymore, other people forked and are now maintained them. So we recommend you to do the same if you care about memoize this much;

@dimko

You can also use begin end for more complex cases:

def memoizable
  @memoizable ||= begin
    ...
  end
end
@pboling

Thanks @matthewrudy I just noticed your extraction, and will use it!

@MGPalmer

@pboling, That repo is dead, the nearest thing I could find is https://github.com/JackDanger/simple_memoize .

@matthewrudy

@MGPalmer I moved it to https://github.com/matthewrudy/memoist.
This codebase is exactly the same as that in ActiveSupport, except for the namespace.

The tests and authors have been copied straight from the rails project.

@roryokane

The comments on the commit when ActiveSupport::Memoizable was deprecated also discuss this change.

Please sign in to comment.