diff options
author | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-10-22 14:27:55 -0500 |
---|---|---|
committer | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-10-22 14:27:55 -0500 |
commit | 2ef4d5ed5cbbb2a9266c99535e5f51918ae3e3b6 (patch) | |
tree | 406457f6157c5b6b6ec86572ac9fb748b6a50422 /guides/source | |
parent | 77eb1fb22d0f25183eb608b8ae55d9f1eb8bec59 (diff) | |
download | rails-2ef4d5ed5cbbb2a9266c99535e5f51918ae3e3b6.tar.gz rails-2ef4d5ed5cbbb2a9266c99535e5f51918ae3e3b6.tar.bz2 rails-2ef4d5ed5cbbb2a9266c99535e5f51918ae3e3b6.zip |
fix output messages - docs [ci skip]
Diffstat (limited to 'guides/source')
-rw-r--r-- | guides/source/active_record_validations_callbacks.md | 4 | ||||
-rw-r--r-- | guides/source/active_support_core_extensions.md | 36 | ||||
-rw-r--r-- | guides/source/active_support_instrumentation.md | 4 | ||||
-rw-r--r-- | guides/source/i18n.md | 2 |
4 files changed, 23 insertions, 23 deletions
diff --git a/guides/source/active_record_validations_callbacks.md b/guides/source/active_record_validations_callbacks.md index 7555ef4226..5c27ccbf9e 100644 --- a/guides/source/active_record_validations_callbacks.md +++ b/guides/source/active_record_validations_callbacks.md @@ -736,7 +736,7 @@ end person = Person.new person.valid? # => false person.errors - # => {name: ["can't be blank", "is too short (minimum is 3 characters)"]} + # => {:name=>["can't be blank", "is too short (minimum is 3 characters)"]} person = Person.new(name: "John Doe") person.valid? # => true @@ -1003,7 +1003,7 @@ Callbacks can also be registered to only fire on certain lifecycle events: ```ruby class User < ActiveRecord::Base before_validation :normalize_name, on: :create - + # :on takes an array as well after_validation :set_location, on: [ :create, :update ] diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index c08ad1ee90..e7ed62ef47 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -2372,7 +2372,7 @@ This method is similar in purpose to `Kernel#Array`, but there are some differen The last point is particularly worth comparing for some enumerables: ```ruby -Array.wrap(foo: :bar) # => [{foo: :bar}] +Array.wrap(foo: :bar) # => [{:foo=>:bar}] Array(foo: :bar) # => [[:foo, :bar]] ``` @@ -2557,7 +2557,7 @@ Ruby has a built-in method `Hash#merge` that merges two hashes: ```ruby {a: 1, b: 1}.merge(a: 0, c: 2) -# => {a: 0, b: 1, c: 2} +# => {:a=>0, :b=>1, :c=>2} ``` Active Support defines a few more ways of merging hashes that may be convenient. @@ -2602,7 +2602,7 @@ Active Support defines `Hash#deep_merge`. In a deep merge, if a key is found in ```ruby {a: {b: 1}}.deep_merge(a: {c: 2}) -# => {a: {b: 1, c: 2}} +# => {:a=>{:b=>1, :c=>2}} ``` The method `deep_merge!` performs a deep merge in place. @@ -2641,17 +2641,17 @@ The method `diff` returns a hash that represents a diff of the receiver and the # => {}, first rule {a: 1}.diff(a: 2) -# => {a: 1}, second rule +# => {:a=>1}, second rule {a: 1}.diff(b: 2) -# => {a: 1, b: 2}, third rule +# => {:a=>1, :b=>2}, third rule {a: 1, b: 2, c: 3}.diff(b: 1, c: 3, d: 4) -# => {a: 1, b: 2, d: 4}, all rules +# => {:a=>1, :b=>2, :d=>4}, all rules {}.diff({}) # => {} -{a: 1}.diff({}) # => {a: 1} -{}.diff(a: 1) # => {a: 1} +{a: 1}.diff({}) # => {:a=>1} +{}.diff(a: 1) # => {:a=>1} ``` An important property of this diff hash is that you can retrieve the original hash by applying `diff` twice: @@ -2671,7 +2671,7 @@ NOTE: Defined in `active_support/core_ext/hash/diff.rb`. The method `except` returns a hash with the keys in the argument list removed, if present: ```ruby -{a: 1, b: 2}.except(:a) # => {b: 2} +{a: 1, b: 2}.except(:a) # => {:b=>2} ``` If the receiver responds to `convert_key`, the method is called on each of the arguments. This allows `except` to play nice with hashes with indifferent access for instance: @@ -2776,7 +2776,7 @@ The method `symbolize_keys` returns a hash that has a symbolized version of the ```ruby {nil => nil, 1 => 1, "a" => "a"}.symbolize_keys -# => {1 => 1, nil => nil, a: "a"} +# => {1=>1, nil=>nil, :a=>"a"} ``` WARNING. Note in the previous example only one key was symbolized. @@ -2785,7 +2785,7 @@ The result in case of collision is undefined: ```ruby {"a" => 1, a: 2}.symbolize_keys -# => {a: 2}, in my test, can't rely on this result though +# => {:a=>2}, in my test, can't rely on this result though ``` This method may be useful for example to easily accept both symbols and strings as options. For instance `ActionController::UrlRewriter` defines @@ -2836,17 +2836,17 @@ Ruby has built-in support for taking slices out of strings and arrays. Active Su ```ruby {a: 1, b: 2, c: 3}.slice(:a, :c) -# => {c: 3, a: 1} +# => {:c=>3, :a=>1} {a: 1, b: 2, c: 3}.slice(:b, :X) -# => {b: 2} # non-existing keys are ignored +# => {:b=>2} # non-existing keys are ignored ``` If the receiver responds to `convert_key` keys are normalized: ```ruby {a: 1, b: 2}.with_indifferent_access.slice("a") -# => {a: 1} +# => {:a=>1} ``` NOTE. Slicing may come in handy for sanitizing option hashes with a white list of keys. @@ -2855,8 +2855,8 @@ There's also `slice!` which in addition to perform a slice in place returns what ```ruby hash = {a: 1, b: 2} -rest = hash.slice!(:a) # => {b: 2} -hash # => {a: 1} +rest = hash.slice!(:a) # => {:b=>2} +hash # => {:a=>1} ``` NOTE: Defined in `active_support/core_ext/hash/slice.rb`. @@ -2867,8 +2867,8 @@ The method `extract!` removes and returns the key/value pairs matching the given ```ruby hash = {a: 1, b: 2} -rest = hash.extract!(:a) # => {a: 1} -hash # => {b: 2} +rest = hash.extract!(:a) # => {:a=>1} +hash # => {:b=>2} ``` The method `extract!` returns the same subclass of Hash, that the receiver is. diff --git a/guides/source/active_support_instrumentation.md b/guides/source/active_support_instrumentation.md index b35691bbcc..1163940f10 100644 --- a/guides/source/active_support_instrumentation.md +++ b/guides/source/active_support_instrumentation.md @@ -434,7 +434,7 @@ ActiveSupport::Notifications.subscribe "process_action.action_controller" do |*a event.name # => "process_action.action_controller" event.duration # => 10 (in milliseconds) - event.payload # => { extra: :information } + event.payload # => {:extra=>information} Rails.logger.info "#{event} Received!" end @@ -477,7 +477,7 @@ Now you can listen to this event with: ```ruby ActiveSupport::Notifications.subscribe "my.custom.event" do |name, started, finished, unique_id, data| - puts data.inspect # { this: :data } + puts data.inspect # {:this=>:data} end ``` diff --git a/guides/source/i18n.md b/guides/source/i18n.md index e916bda630..9d8287ab7c 100644 --- a/guides/source/i18n.md +++ b/guides/source/i18n.md @@ -546,7 +546,7 @@ Also, a key can translate to a (potentially nested) hash of grouped translations ```ruby I18n.t 'activerecord.errors.messages' -# => { inclusion: "is not included in the list", exclusion: ... } +# => {:inclusion=>"is not included in the list", :exclusion=> ... } ``` #### "Lazy" Lookup |