Your item
variable holds Array
instance (in [hash_key, hash_value]
format), so it doesn’t expect Symbol
in []
method.
This is how you could do it using Hash#each
:
def format(hash) output = Hash.new hash.each do |key, value| output[key] = cleanup(value) end output end
or, without this:
def format(hash) output = hash.dup output[:company_name] = cleanup(output[:company_name]) output[:street] = cleanup(output[:street]) output end
Related Posts:
- Why does Ruby on Rails use http://0.0.0.0:3000 instead of http://localhost:3000?
- Unable to install gem – Failed to build gem native extension – cannot load such file — mkmf (LoadError)
- Cannot load such file — bcrypt_ext
- How do I remove Permission denied @ rb_sysopen – Gem install error?
- warning: constant ::Fixnum is deprecated When generating new model
- bcrypt LoadError: Cannot load such file
- Uninitialized constant “Controller Name”
- Difference between rake db:migrate db:reset and db:schema:load
- Migrations are pending; run ‘bin/rake db:migrate RAILS_ENV=development’ to resolve this issue
- 400 Bad Request – request header or cookie too large
- Why Puma listen on ‘tcp://localhost:3000’ instead of ‘http://localhost:3000’
- Explain what " means
- ActionController::InvalidAuthenticityToken
- bundle install returns “Could not locate Gemfile”
- ActionController::InvalidAuthenticityToken
- Rails: Why “sudo” command is not recognized?
- Rails 5 ActionController::InvalidAuthenticityToken error
- what does ? ? mean in ruby
- Rails: Can’t verify CSRF token authenticity when making a POST request
- undefined method `each’ for nil:NilClass… why?
- Bundler: You must use Bundler 2 or greater with this lockfile
- undefined method `each’ for nil:NilClass… why?
- Using Pundit for all-access “super_admin” role
- How to tell if homebrew is installed on Mac OS X
- What is the difference between Rails.cache.clear and rake tmp:cache:clear?
- Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib
- Can’t find the ‘libpq-fe.h header when trying to install pg gem
- could not connect to server: No such file or directory (PG::ConnectionBad)
- PG::ConnectionBad: fe_sendauth: no password supplied
- curl : (1) Protocol https not supported or disabled in libcurl
- Rails 4 RoutingError: No Route Matches
- couldn’t find file ‘jquery’ with type ‘application/javascript’
- Passing parameters in rails redirect_to
- Getting: “Migrations are pending; run ‘bin/rake db:migrate RAILS_ENV=development’ to resolve this issue.” after cloning and migrating the project
- PG::ConnectionBad – could not connect to server: Connection refused
- Rails syntax error : unexpected keyword_ensure, expecting end-of-input
- How to find out which rails version an existing rails application is built on?
- RubyMine Unit tests – Test Framework quit unexpectedly
- Ruby: What is the easiest way to remove the first element from an array?
- How do I format datetime in rails?
- Ruby String to Date Conversion
- heroku open – no app specified
- Sass::SyntaxError: File to import not found or unreadable: bootstrap-sprockets
- Rails button_to vs. HTML Button Tag
- GROUP BY and COUNT using ActiveRecord
- How to stop (and restart) the Rails Server?
- Uploading a file in Rails
- An error occurred while installing json (1.8.1), and Bundler cannot continue – Rails
- Nginx error: client intended to send too large body
- How do I parse JSON with Ruby on Rails? [duplicate]
- Get underlined text with Markdown
- Advanced AREL or just Rails Query for has_many through search by association
- What is the meaning of *nix?
- What does the “map” method do in Ruby?
- AngularJS- Login and Authentication in each route and controller
- Ruby: Can I write multi-line string with no concatenation?
- Getting error: Peer authentication failed for user “postgres”, when trying to get pgsql working with rails
- How to update Ruby Version 2.0.0 to the latest version in Mac OSX Yosemite?
- Why use Ruby’s attr_accessor, attr_reader and attr_writer?
- How to update Ruby with Homebrew?
- How to use “gets” and “gets.chomp” in Ruby
- Getting a substring in Ruby by x number of chars
- How to check whether a string contains a substring in Ruby
- Ruby: How to install a specific version of a ruby gem?
- class << self idiom in Ruby
- What does << mean in Ruby?
- What does ||= (or-equals) mean in Ruby?
- How to map with index in Ruby?
- Difference between `not` and `!` in ruby
- How to sum array of numbers in Ruby?
- Ruby array to string conversion
- How to check if a value exists in an array in Ruby
- undefined method (NoMethodError) ruby
- Multi-Line Comments in Ruby?
- How to uninstall ruby installed by ruby-install
- Removing all installed Gems and starting over
- Ruby `send` vs `call` method
- Rails: I installed Ruby, now “bundle install” doesn’t work
- Devise lockable – How to unlock account using unlock_in
- How to do a newline in output
- Determining type of an object in ruby
- What does @@variable mean in Ruby?
- “Error installing rails” because “extconf.rb failed” on Ubuntu 18.04
- What does the Ruby method ‘to_sym’ do?
- Difference between map and collect in Ruby?
- Array to Hash Ruby
- Purge or recreate a Ruby on Rails database
- Getting error: dyld: Symbol not found: _clock_gettime
- How to run Ruby code from terminal?
- Uninstall old versions of Ruby gems
- Generate model in Rails using user_id:integer vs user:references
- How can I delete one element from an array by value
- What is the difference between “rake db:seed” and rake db:fixtures:load”
- ERROR: While executing gem … (Gem::FilePermissionError)
- No such file or directory @ rb_sysopen ruby
- How to add to an existing hash in Ruby
- How to convert a string to lower or upper case in Ruby
- What is the canonical way to trim a string in Ruby without creating a new string?
- No implicit conversion of String into Integer (TypeError)?
- Multi-Line Comments in Ruby?