王筝的博客
ruby学习

 

dig(key, …) → objectclick to toggle source

Extracts the nested value specified by the sequence of idx objects by calling dig at each step, returning nil if any intermediate step is nil.

http://ruby-doc.org/core-2.4.0/Hash.html#method-i-dig

h = { foo: {bar: {baz: 1}}}

h.dig(:foo, :bar, :baz)           #=> 1
h.dig(:foo, :zot, :xyz)           #=> nil

g = { foo: [10, 11, 12] }
g.dig(:foo, 1)                    #=> 11
g.dig(:foo, 1, 0)                 #=> TypeError: Integer does not have #dig method
g.dig(:foo, :bar)                 #=> TypeError: no implicit conversion of Symbol into Integer

举例子:

            if item["ui_type"]["pos"].present?
              display_item.x_axis = item["ui_type"]["pos"]["x"] if item["ui_type"]["pos"]["x"].present?
              display_item.y_axis = item["ui_type"]["pos"]["y"] if item["ui_type"]["pos"]["y"].present?
              display_item.width = item["ui_type"]["pos"]["w"]  if item["ui_type"]["pos"]["w"].present?
              display_item.height = item["ui_type"]["pos"]["h"] if item["ui_type"]["pos"]["h"].present?
            end

改为

         display_item.x_axis = item["ui_type"]["pos"]["x"] if item.dig("ui_type", "pos", "x").present?
         display_item.y_axis = item["ui_type"]["pos"]["y"] if item.dig("ui_type", "pos", "y").present?
         display_item.width = item["ui_type"]["pos"]["w"]  if item.dig("ui_type", "pos", "w").present?
         display_item.height = item["ui_type"]["pos"]["h"] if item.dig("ui_type", "pos", "h").present?

 

 

 

$ git checkout -b cibn-cache-clean
Switched to a new branch ‘cibn-cache-clean’
$ git cherry-pick 9b78e3f6e70cf8ad9bd85b90e36819ea6a77ed32
[cibn-cache-clean bd0c3d2] Add subject cache clear link

 

 

修改git最后一次提交的命令

$ git commit --amend

修改git最后一次提交用户名的相关命令

git config user.name 'wangz'  
git config user.email 'wangz@alib.com'  
git commit  --amend --author=wangz

修改最后一次提交内容的相关文档

$ git commit --amend --help  
usage: git commit [options] [--] <pathspec>...

    -q, --quiet           suppress summary after successful commit
    -v, --verbose         show diff in commit message template

Commit message options
    -F, --file <file>     read message from file
    --author <author>     override author for commit
    --date <date>         override date for commit
    -m, --message <message>
                          commit message
    -c, --reedit-message <commit>
                          reuse and edit message from specified commit
    -C, --reuse-message <commit>
                          reuse message from specified commit
    --fixup <commit>      use autosquash formatted message to fixup specified commit
    --squash <commit>     use autosquash formatted message to squash specified commit
    --reset-author        the commit is authored by me now (used with -C/-c/--amend)
    -s, --signoff         add Signed-off-by:
    -t, --template <file>
                          use specified template file
    -e, --edit            force edit of commit
    --cleanup <default>   how to strip spaces and #comments from message
    --status              include status in commit message template
    -S, --gpg-sign[=<key id>]
                          GPG sign commit

Commit contents options
    -a, --all             commit all changed files
    -i, --include         add specified files to index for commit
    --interactive         interactively add files
    -p, --patch           interactively add changes
    -o, --only            commit only specified files
    -n, --no-verify       bypass pre-commit hook
    --dry-run             show what would be committed
    --short               show status concisely
    --branch              show branch information
    --porcelain           machine-readable output
    --long                show status in long format (default)
    -z, --null            terminate entries with NUL
    --amend               amend previous commit
    --no-post-rewrite     bypass post-rewrite hook
    -u, --untracked-files[=<mode>]
                          show untracked files, optional modes: all, normal, no. (Default: all)

 

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /Users/angela/.rbenv/versions/1.9.3-p545/bin/ruby -r ./siteconf20170106-59264-robjdg.rb extconf.rb --use-system-libraries
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using system libraries.
libxml2 version 2.6.21 or later is required!
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/angela/.rbenv/versions/1.9.3-p545/bin/ruby
    --help
    --clean
    --use-system-libraries
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --with-xml2-dir
    --without-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib
    --without-xml2-lib=${xml2-dir}/lib
    --with-libxml-2.0-config
    --without-libxml-2.0-config
    --with-pkg-config
    --without-pkg-config
    --with-xslt-dir
    --without-xslt-dir
    --with-xslt-include
    --without-xslt-include=${xslt-dir}/include
    --with-xslt-lib
    --without-xslt-lib=${xslt-dir}/lib
    --with-libxslt-config
    --without-libxslt-config
    --with-exslt-dir
    --without-exslt-dir
    --with-exslt-include
    --without-exslt-include=${exslt-dir}/include
    --with-exslt-lib
    --without-exslt-lib=${exslt-dir}/lib
    --with-libexslt-config
    --without-libexslt-config

extconf failed, exit code 1

Gem files will remain installed in /Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/nokogiri-1.6.7.2 for inspection.
Results logged to /Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/extensions/x86_64-darwin-13/1.9.1-static/nokogiri-1.6.7.2/gem_make.out
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:89:in `run'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/ext_conf_builder.rb:36:in `block in build'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/tempfile.rb:320:in `open'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/ext_conf_builder.rb:19:in `build'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:161:in `block (2 levels) in build_extension'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:160:in `chdir'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:160:in `block in build_extension'
<internal:prelude>:10:in `synchronize'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:159:in `build_extension'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:198:in `block in build_extensions'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:195:in `each'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:195:in `build_extensions'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:702:in `build_extensions'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:250:in `install'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/source/rubygems.rb:90:in `block in install'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/rubygems_integration.rb:130:in `preserve_paths'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/source/rubygems.rb:89:in `install'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/installer.rb:105:in `block in install_gem_from_spec'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/rubygems_integration.rb:162:in `with_build_args'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/installer.rb:104:in `install_gem_from_spec'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/installer.rb:262:in `block in install_sequentially'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/forwardable.rb:201:in `each'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/forwardable.rb:201:in `each'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/installer.rb:261:in `install_sequentially'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/installer.rb:91:in `run'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/installer.rb:15:in `install'
/Users/angela/.rbenv/rbenv.d/exec/gem-rehash/rubygems_plugin.rb:27:in `install'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/cli/install.rb:78:in `run'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/cli.rb:145:in `install'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/vendor/thor/command.rb:27:in `run'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/vendor/thor/invocation.rb:121:in `invoke_command'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/vendor/thor.rb:363:in `dispatch'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/vendor/thor/base.rb:440:in `start'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/cli.rb:9:in `start'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/bin/bundle:20:in `block in <top (required)>'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/friendly_errors.rb:5:in `with_friendly_errors'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/bin/bundle:18:in `<top (required)>'
/Users/angela/.rbenv/versions/1.9.3-p545/bin/bundle:23:in `load'
/Users/angela/.rbenv/versions/1.9.3-p545/bin/bundle:23:in `<main>'
An error occurred while installing nokogiri (1.6.7.2), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.7.2'` succeeds before bundling.

解决方法

brew install --force libxml2 libxslt
brew install --force libiconv

xcode-select --install