Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update CHANGELOG, improve message.

  • Loading branch information...
commit 8775ffa37231d381cba34f0ecacb8a7bbcf0573f 1 parent 43ed24e
José Valim josevalim authored
4 activesupport/CHANGELOG
View
@@ -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]
Piotr Sarnacki Collaborator
drogus added a note

Y U NO LIKE BRITISH ENGLISH?! :(

AKA actual English.

Piotr Sarnacki Collaborator
drogus added a note

:D

Piotr Sarnacki Collaborator
drogus added a note

I smell a war ;) /cc @jonleighton

José Valim Owner

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

Piotr Sarnacki Collaborator
drogus added a note

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

José Valim Owner

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]
2  activesupport/lib/active_support/memoizable.rb
View
@@ -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

SengMing Tan

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

Peter Boling

"simply use Ruby memoization pattern instead."

Memoization is now part of standard Ruby.

Matthew Rudy Jacobs

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.

Peter Boling

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
Matthew Rudy Jacobs

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.

José Valim
Owner
def to_params
  @to_params ||= to_hash.map do |key, value|
    "#{key}=#{value}"
  end.join("&")
end

FTFY.

Matthew Rudy Jacobs

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

Peter Boling

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.

José Valim
Owner

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;

DM

You can also use begin end for more complex cases:

def memoizable
  @memoizable ||= begin
    ...
  end
end
Piotr Sarnacki

Y U NO LIKE BRITISH ENGLISH?! :(

Stevie Graham

AKA actual English.

Piotr Sarnacki

:D

Piotr Sarnacki

I smell a war ;) /cc @jonleighton

José Valim

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

Piotr Sarnacki

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

José Valim

Bugger off!

Peter Boling

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

Oh no you don't

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

Matthew Rudy Jacobs

@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.

Rory O’Kane

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

Please sign in to comment.
Something went wrong with that request. Please try again.