Questions tagged [ruby-2.1]

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

Ruby is a dynamic, open source programming language with a focus on simplicity and productivity. Ruby 2.1 was released on Dec 25, 2013.

For information on Ruby in general, visit .

222 questions
0
votes
2 answers

Ruby 2.1 Frozen string

Ruby 2.1 will have a frozen string so that the object is not re-created every time that the interpreter runs across it, i.e. my_hash["abcd"f] = 123 Why can't the interpreter automatically detect that this string is not going to change and just…
Daniel
  • 7,006
  • 7
  • 43
  • 49
-1
votes
2 answers

What does Array#reverse method in Ruby do?

In Ruby, when I call reverse method on an array, it doesn't reverse sort the array completely. array = [5, 4, 9, 8, 7, 1, 2] array.reverse # => [2, 1, 7, 8, 9, 4, 5] I'm unable to understand what operation it's performing on the array.
-1
votes
2 answers

Trying to run an existing application and getting (Psych::SyntaxError)

The application is running on the a web server properly and I tried to run it locally and I am getting these errors. Any idea what the issue might be? I am new to Ruby, so please excuse me if this is a simple question…
herk
  • 15
  • 6
-1
votes
1 answer

why cannot reassign class variables in controller of rails

I have a base controller class Base @@var = 'base' def self.result @@var end def self.result=(var) @@var = var end def do_sth // do something here end end and 2 subclasses class A < Base Base.result = 'a' end class B…
worldask
  • 1,837
  • 3
  • 22
  • 37
-1
votes
1 answer

How to write a script that can deal with input in the format of ARGF as well as file in Ruby

Is there a concise way to do it? case 1 File.open(infile, 'r').readlines.each do |line| process end case 2 ARGF.readlines.each do |line| process end
user3477465
  • 183
  • 2
  • 2
  • 6
-1
votes
1 answer

Prawn in a Ruby on Rails app, failing on production

I am stuck on an issue with running prawn in production. I have followed the Railscast (revised http://railscasts.com/episodes/153-pdfs-with-prawn-revised?view=asciicast) pretty much to the letter. It works great in my development environment (Mac…
humbledaisy
  • 373
  • 1
  • 3
  • 12
-2
votes
3 answers

How to modify arrays of hashes in ruby 2.1.2?

I have an array of hashes called array_of_hash: array_of_hash = [ {:name=>"1", :address=>"USA", :collection=>["LAND", "WATER", "OIL", "TREE", "SAND"], :sequence=>"AB"}, {:name=>"5", :address=>"UK", :collection=>["LAND", "WATER", "OIL", "TREE",…
kavin
  • 3
  • 5
-2
votes
1 answer

How to use the gems of Ruby 2.1 in Ruby 1.9 in batch

I have both Ruby 1.9 and 2.1 installed in my computer. Now I am wanting to use several of the gems installed for Ruby 2.1 in Ruby 1.9. However, Ruby 1.9 can't find them. I tried to solve this problem by setting the environmental variable RUBYLIB…
user3476791
  • 1,072
  • 1
  • 9
  • 14
-2
votes
1 answer

Ruby ternary operator and method call

I am using ruby 2.1.5, facing some problem with ternary operator Syntax error request.xhr? ? render :json => "success" : redirect_to index_url working request.xhr? ? render(:json => "success") : redirect_to(index_url) Can some please explain…
Ram Kumar
  • 94
  • 7
-2
votes
2 answers

Why does app go to the create.html.erb view after post submission instead of show.html.erb view? rails 4

Right now in my rails 4 app after the user submits a post I want the app to redirect/render the show view, but right now it just goes to the create view. Here is my Posts controller: class PostsController < ApplicationController def show …
tomcruise
  • 17
  • 1
  • 7
-4
votes
1 answer

Syntax error, unexpected ':', expecting ')' - Rails 2.1.0

Getting a syntax error when running rake tasks: bundle exec rake test:read_message ruby -v 2.1.0 /ruby/gems/2.1.0/gems/spring-1.7.1/lib/spring/client/run.rb:76: syntax error, unexpected ':', expecting ')' (SyntaxError) ..._env,…
Bahubali
  • 1
  • 2
-4
votes
2 answers

What is the clearest way to define two dimensional array in Ruby?

I have an array a=[0,1,2]. Now I want to add a new element to A[0] and make it a[0]=[0] I want to do use a[0].push(0), however, I have to define a[0] as an array, so my code will be something like: a=[0,1,2] a[0]=[] for i in 1..100; do a[0].push(i);…
user3477465
  • 183
  • 2
  • 2
  • 6
1 2 3
14
15