Going through the Active Support Core Extensions guide , it looks like some of them are not available. Here's verbatim output from a new session:
$ rails --version
Rails 3.1.3
$ rails console
[1] pry(main)> [].prepend(10)
NoMethodError: undefined method `prepend' for []:Array
from (pry):1:in `<main>'
[2] pry(main)> [].unshift(10)
=> [10]
[3] pry(main)> %w(a b c d).append('e')
NoMethodError: undefined method `append' for ["a", "b", "c", "d"]:Array
from (pry):3:in `<main>'
[4] pry(main)> %w(a b c d) << 'e'
=> ["a", "b", "c", "d", "e"]
[5] pry(main)> require 'active_support/core_ext/array'
=> false
There's nothing indicating that append
and prepend
are deprecated or cutting-edge only, so what is happening here?
Looks like these are actually not part of Rails 3.1.3, because these fail:
$ grep 'prepend\|append' ~/.rvm/gems/ruby-1.9.3-p0@project_name/gems/activesupport-3.1.3/lib/active_support/core_ext/array/*
$ ls ~/.rvm/gems/ruby-1.9.3-p0@taclom/gems/activesupport-3.1.3/lib/active_support/core_ext/array/prepend_and_append.rb
看起来它仅在Rails v3.2.1中可用。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.