I need a way to split an array in to an exact number of smaller arrays of roughly-equal size. Anyone have any method of doing this?
For instance
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
groups = a.method_i_need(3)
groups.inspect
=>…
I'm not a Ruby dev by trade, but am using Capistrano for PHP deployments. I'm trying to cleanup the output of my script and am trying to add a unicode check mark as discussed in this blog.
The problem is if I do:
checkmark = "\u2713"
puts…
I want to get the last character in a string MY WAY - 1) Get last index 2) Get character at last index, as a STRING. After that I will compare the string with another, but I won't include that part of code here. I tried the code below and I get a…
So I'm writing some rspec tests and I'm embarrassed at my lack of Ruby understanding.
I have a file structure that looks like the following:
GUI_Tests/Tests/test_spec.rb
GUI_Tests/windows_gui.rb
GUI_Tests/upload_tool.rb
when I run spec for the…
I wasn't working with ruby 1.8.7 and recently I was surprised that:
{:k => 30}.to_s #=> "k30"
Is there ready to use fix to convert hash to string for ruby 1.8.7 to make it look like:
{:k => 30}.to_s #=> "{:k=>30}"
I am in a process of migrating my application from ruby 1.8.7 to 1.9.3 (and later upgrading Rails). However I geht some problems with logging in 1.9.3.
By using the following code in environment.rb when console or server starts up
logfile =…
I'm using Rails 3.2.2, with aasm gem, I have Document model this way:
class Document < ActiveRecord::Base
include AASM
aasm do
state :unread, :initial => true
state :read
state :closed
event :view do
transitions :to =>…
I'm trying to make a https post request in ruby and it works in curl, but I get a 400 bad request in ruby and I'm having trouble figuring out why.
Heres the ruby code:
require 'rubygems'
require 'net/https'
require 'uri'
require 'json'
uri =…
Note: This question relates to How can I get bundler to use the Ruby version set by chruby and .ruby-version?.
Using chruby I have Ruby 1.8.7 installed on macOS:
$ ruby -v
ruby 1.8.7 (2013-06-27 patchlevel 374) [i686-darwin17.4.0]
Also, I have used…
Is there a spawn equivalent for ruby 1.8.7?
It appears as though it was introduced in 1.9.1
http://apidock.com/ruby/Kernel/spawn
I need the following to work in ruby 1.8.7:
def run_worker(queue, count = 1)
puts "Starting #{count} worker(s) with…
I have a Rails app using Ruby 1.8.7 and I'm getting this error when running in debug mode and setting a break point:
54749: Exception in DebugThread loop: undefined method `errmsg' for…
In Ruby 1.8.7 and prior, Enumerable::each_with_index did not accept any arguments. In Ruby 1.9, it will accept an arbitrary number of arguments. Documentation/code shows that it simply passes those arguments along to ::each. With the built in and…
Please help me out with this, jquery is working well in w3schools but in my rails 2 app its getting error like check not defined
Here is my html code:
Checkbox:
I execute the following code in ruby 1.8.7 to read rows from my database:
require 'dbi'
db_conn_handle = DBI.connect("DBI:Mysql:host=localhost;database=mydb;port=3306", "root")
sth = db_conn_handle.prepare("select accounts.id, accounts.name from…