Questions tagged [ruby-2.2]

For issues relating to development in Ruby, version 2.2. If your question applies to Ruby in general, use the tag [tag:ruby].

For issues relating to development in Ruby, version 2.2. It was released on December 2014. You can check the official docs here.

If your question applies to Ruby in general, use the tag .

119 questions
2
votes
3 answers

Open3.popen3 returns wrong error Errno::ENOENT on Windows

I have the following code in test.rb: require 'open3' cmd = 'C:\Program Files\foo\bar.exe' Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr| puts "stdout: #{stdout.read}" puts "\n\n" puts "stderr: #{stderr.read}" end bar.exe is a console…
dhrubo_moy
  • 1,144
  • 13
  • 31
2
votes
1 answer

Why the following works in ruby?

to_a over a range of integers behaves differently in this case. Upto 15 decimals, include? returns false but once it reached 16 decimals array considers the decimal digit as part of array. Why? 2.2.1 :020 > (1..9).to_a.include?(8.999999999999999) …
swapab
  • 2,402
  • 1
  • 27
  • 44
2
votes
1 answer

Ruby 2 intercepting request with Typhoeus

I want to change query params before request is hit using typhoeus. What should be right approach? Do we have interceptors in Ruby as that of Java, should I be using something like before_filter as that in Rails or meta-programming in Ruby? I just…
S R
  • 674
  • 2
  • 18
  • 45
2
votes
1 answer

How to create an instance of an associated model when using a has_many :through association

I have two models (Called User and Plan) that I have associated by using a has_many :through association (called Participation). A plan should be created by a user and therefore I want to know: How to create an instance of the model Plan and an an…
2
votes
3 answers

Elegant way in Ruby to find first of possible matching hash keys

Lets say I have user input that can be either this: input = { user_id: 5, ... } or this: input = { app_id: 5, ... } And I want to return either :user_id or :app_id depending on which is provided. I can do this: (input.keys & [:user_id,…
Ben
  • 432
  • 5
  • 16
2
votes
0 answers

ActiveModelSerializers (0.10.0.rc3) an object's relation's relation is not generated with default FlattenJson adapter

Rails 5 Alpha version / Ruby 2.2.3 / active_model_serializers (0.10.0.rc3) (henceforth referred as AMS) GIT remote: https://github.com/rails/rails.git revision: 5217db2a7acb80b18475709018088535bdec6d30 GEM remote: https://rubygems.org/ …
Jignesh Gohel
  • 6,236
  • 6
  • 53
  • 89
2
votes
2 answers

How to suppress stacktrace in Ruby exit?

trap 'TERM' do warn 'Exiting.' exit 1 end This prints a 10 line stacktrace. How to suppress the stacktrace and exit silently? Ruby 2.2.0
B Seven
  • 44,484
  • 66
  • 240
  • 385
2
votes
2 answers

Ruby unit testing - access test result (success/failure)?

I'm using Ruby 2.2. I need to run a unit test and get information if it succeeded or failed. I'm browsing through docs of both test-unit and minitest (suggested gems for unit testing in Ruby 2.2) but I can't seem to find a method that would return…
charlie
  • 45
  • 6
2
votes
2 answers

Ruby refinement issues with respond_to? and scoping

I'm trying to add an instance method foo to Ruby's Array class so when it's invoked, the array's string elements are changed to string "foo". This can be done easily by monkey patching Ruby's String and Array classes. class String def foo …
Zack Xu
  • 11,505
  • 9
  • 70
  • 78
2
votes
1 answer

How to save url encoded emoji as text (eg "%F0%9F%98%80") in Postgres? (RoR)

I'm struggling to save url encoded emoji as text. I use PostgreSQL, Ruby 2.2.2, Rails 4.1.9. To encode/decode emoji I use ERB::Util module http://ruby-doc.org/stdlib-2.2.2/libdoc/erb/rdoc/ERB/Util.html On save this "%F0%9F%98%80" changes to…
Anita
  • 53
  • 8
2
votes
3 answers

How to restrict user to search for a particular model in view?

Application I am working has different user roles client, project manager and super user and on landing page they can search for Articles and there is an advanced filter to filter out records after search. Like: Filter by Author. I want to hide…
Pardeep Dhingra
  • 3,916
  • 7
  • 30
  • 56
2
votes
5 answers

Convert array of arrays to hash with first array's element as a key to the hash

I want to convert this array [['a', 'b'],['c', 'd'],['e', 'f']] to this hash { "a" : "c", "b" : "d" }, { "a" : "e", "b" : "f" } How to do it? I tried to use group_by and normal iterators but no luck so far. Any ideas?
Ahmad hamza
  • 1,816
  • 1
  • 23
  • 46
2
votes
2 answers

Regex to match time ranges involving am/pm like 7am-10pm

I have written the following regex (1[012]|[1-9])(am|pm)\-(1[012]|[1-9])(am|pm) to match following kind of time formats: 7am-10pm (matches correctly and creates 4 match groups 7, am, 10, pm) 13am-10pm (this should not be matched, however it…
Jignesh Gohel
  • 6,236
  • 6
  • 53
  • 89
2
votes
3 answers

How can we avoid duplication/repeatition of methods in controllers - RAILS 3+

I am building a sample e-commerce app using ruby on rails.One of my controller name is "products_controller".This controller is also placed inside as a nested controller.The actions inside these controllers are same.How can we represent these…
2
votes
4 answers

ruby on rails AbstractController::Helpers::MissingHelperError: Missing helper file helpers//

I just cloned a repository I was working on from another computer. When I try to do a database migration by running 'rake db:migrate' I get the following error: AbstractController::Helpers::MissingHelperError: Missing helper file…
Philip7899
  • 4,599
  • 4
  • 55
  • 114