activesupport

3.days.ago, 2.hours.from_now etc without Rails?

蓝咒 提交于 2019-12-03 09:29:24
Some book mentioned some gem to decorate numbers with #days , #megabytes , #minutes etc. Is this only in ActiveSupport, or is there a smaller gem that provides this functionality for use in (small) non-rails gems? I want to use this functionality as part of a DSL in a tiny little gem. Michael Kohl I'm not sure if there's another gem available besides ActiveSupport , but it would be really straight-forward to make a small version yourself: class Fixnum SECONDS_IN_DAY = 24 * 60 * 60 def days self * SECONDS_IN_DAY end def ago Time.now - self end end 3.days.ago #=> 2011-06-18 08:45:29 0200 from

What do I need to do to get Hash.from_xml() to work?

依然范特西╮ 提交于 2019-12-03 06:47:15
I installed 'ActiveSupport' and required 'active_support' in my code, but I get a "No Method Error" when I try to use the Hash.from_xml() method. What am I missing? $ gem list returns: \*** LOCAL GEMS \*** activesupport (3.2.6) bundler (1.1.4) i18n (0.6.0) json (1.7.3) mime-types (1.19) multi_json (1.3.6) rake (0.9.2.2) rest-client (1.6.7) rubygems-bundler (1.0.3) rvm (1.11.3.5) And: $ ruby -v returns: ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0] The contents of file.rb are: require 'active_support' require 'rest-client' require 'json' token = "xxx" user = "xxx" survey_id =

What purpose can anonymous modules serve?

心不动则不痛 提交于 2019-12-03 06:37:37
What purpose could anonymous modules in a Ruby app serve? The concept itself is easy to grasp, but I can't imagine any reason that you'd ever use such a thing. What problem do they solve? There is a more general principle at work here. Phil Karlton famously said: "There are only two hard problems computer science: cache invalidation and naming things." So, naming things is hard. Which means that if we can get away with not naming a thing, we should do it! Or, if you look at it from a different perspective: if naming things is hard, then giving something a name means that thing is important.

Which Ruby memoize pattern does ActiveSupport::Memoizable refer to?

坚强是说给别人听的谎言 提交于 2019-12-03 02:10:09
问题 So in Rails 3.2, ActiveSupport::Memoizable has been deprecated. The message reads: DEPRECATION WARNING: ActiveSupport::Memoizable is deprecated and will be removed in future releases,simply use Ruby memoization pattern instead. It refers to "Ruby memoization pattern" (singular) as if there's one pattern we should all know and refer to... I presume they mean something like: def my_method @my_method ||= # ... go get the value end or def my_method return @my_method if defined?(@my_method) @my

Get Time Object at Start of Day in a Particular Time Zone

别等时光非礼了梦想. 提交于 2019-12-02 22:51:12
How can I get a ruby Time object that represents the start of the day on a particular date in a given timezone. date = Date.today date.to_time.in_time_zone('America/New_York').beginning_of_day Currently outputs => 2011-11-02 00:00:00 -0400 Time.now.in_time_zone('Asia/Shanghai').beginning_of_day Currently outputs => 2011-11-03 00:00:00 +0800 date = Date.today date.to_time.in_time_zone('Asia/Shanghai').beginning_of_day Currently outputs => 2011-11-02 00:00:00 +0800 I ended up using the #local method on the ActiveSupport::TimeZone object passing components of the Date object. # Get example date

Which Ruby memoize pattern does ActiveSupport::Memoizable refer to?

岁酱吖の 提交于 2019-12-02 17:15:17
So in Rails 3.2, ActiveSupport::Memoizable has been deprecated. The message reads: DEPRECATION WARNING: ActiveSupport::Memoizable is deprecated and will be removed in future releases,simply use Ruby memoization pattern instead. It refers to "Ruby memoization pattern" (singular) as if there's one pattern we should all know and refer to... I presume they mean something like: def my_method @my_method ||= # ... go get the value end or def my_method return @my_method if defined?(@my_method) @my_method = # ... go get the value end Is there something else I've missed? Here is the commit (and

Can't set timezone using abbreviation

喜欢而已 提交于 2019-12-02 07:43:43
I can't set timezone on Rails using its abbreviation, for example: >> Time.zone = 'BRT' ArgumentError: Invalid Timezone: BRT from /home/braulio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activesupport-3.2.21/lib/active_support/core_ext/time/zones.rb:61:in `rescue in find_zone!' from /home/braulio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activesupport-3.2.21/lib/active_support/core_ext/time/zones.rb:53:in `find_zone!' from /home/braulio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activesupport-3.2.21/lib/active_support/core_ext/time/zones.rb:37:in `zone=' from (irb):14 from /home

Bundler could not find compatible versions for gem “activesupport”

给你一囗甜甜゛ 提交于 2019-12-01 16:37:22
I migrated to 3.2.13 version of rails and I am getting this error, how do I get rid of this? Fetching gem metadata from https://rubygems.org/....... Fetching gem metadata from https://rubygems.org/.. Resolving dependencies... Bundler could not find compatible versions for gem "activesupport": In snapshot (Gemfile.lock): activesupport (3.2.12) In Gemfile: rails (= 3.2.13) ruby depends on activesupport (= 3.2.13) ruby Running `bundle update` will rebuild your snapshot from scratch, using only the gems in your Gemfile, which may resolve the conflict. EDIT sinatra (1.3.6) rack (~> 1.4) rack

NoMethodError: undefined method `halt_callback_chains_on_return_false=' for ActiveSupport:Module

≡放荡痞女 提交于 2019-12-01 16:05:48
I've been developing this RoR 5.1 application for a while, and I need to add a new migration now: class AddActiveFlagToParameters < ActiveRecord::Migration[5.1] def change add_column :parameters, :is_active, :boolean, :default => true end end When I try to run the migration, rails raises the error: NoMethodError: undefined method `halt_callback_chains_on_return_false=' for ActiveSupport:Module Reading around, I finally worked around the issue by upgrading to Rails 5.2 (gem activesupport 5.2.0) and commenting out the line in the file config/initializers/new_framework_defaults.rb But this sounds

NoMethodError: undefined method `halt_callback_chains_on_return_false=' for ActiveSupport:Module

三世轮回 提交于 2019-12-01 15:25:10
问题 I've been developing this RoR 5.1 application for a while, and I need to add a new migration now: class AddActiveFlagToParameters < ActiveRecord::Migration[5.1] def change add_column :parameters, :is_active, :boolean, :default => true end end When I try to run the migration, rails raises the error: NoMethodError: undefined method `halt_callback_chains_on_return_false=' for ActiveSupport:Module Reading around, I finally worked around the issue by upgrading to Rails 5.2 (gem activesupport 5.2.0