I am trying to learn some ruby http request response code from this tutorial -
http://danknox.github.io/2013/01/27/using-rubys-native-nethttp-library/
Code so far -
require "net/http"
require "uri"
uri = URI.parse("http://api.random.com")
http =…
I have a Ruby 1.8.7 script to parse iOS localization files:
singleline_comment = /\/\/(.*)$/
multiline_comment = /\/\*(.*?)\*\//m
string_line = /\s*"(.*?)"\s*=\s*"(.*?)"\s*\;\s*/xm
out =…
Fellow Ruby developers.
I am building a prompt interface with Ruby 1.8.7. As such, I'm using 'readline' in my codes.
As it is a prompt interface I'm building, I want to create an option such that, should a user specify a logfile, all STDOUT and…
I tried this :
irb(main):125:0> a = "ab%c"
=> "ab%c"
irb(main):126:0> a.gsub("%", '\\')
=> "ab\\c"
irb(main):127:0>
whereas expected output is:
ab\c
it did not work.
Thanks in advance.
Update: ruby version
ruby -v
ruby 1.8.7 (2011-06-30 patchlevel…
I want to create an engine for rails app with ruby 1.8.7 and rails 3.0.20 but when I type:
rails plugin new try --full
I get:
/Users/tborisova/.rvm/gems/ruby-1.8.7-p352/gems/railties-3.0.20/lib/rails/commands/plugin.rb:277: Commands is not a module…
Suppose I have an endpoint like so:
get "/foo" do
request.body.rewind
data = request.body.read
# some logic goes here
end
How do I test this in Sinatra?
If I try:
it "gets /foo" do
payload = {:bar => "baz"}
get "/foo",…
ActionView::TemplateError (You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.include?) on line #2 of app/views/layouts/_quick_links.html.erb:
1: <%#*
Right now, I am simply using assert_equal twice - before and after the execution, and it does not hurt much. But I have used RSpec before and liked the readability of the expect{}.to change idiom. I cannot simply use RSpec in this project - not my…
I received a new Macbook Pro for work and started to setup my local machine for development. I installed RVM, then proceeded to install different ruby versions: 2.1, 2.0, 1.9, and 1.8.7. I need 1.8.7 because I will be working on an older site…
I'm working with fog under ruby 1.9 but in our new requirements we need to support ruby 1.8.x. I research and found this (https://github.com/fog/fog#ruby-187) that suggest adding:
gem 'nokogiri', '~>1.5.0'
will solve my problem but I'm still…
Rails 2.3, Ruby 1.8.7
I'm trying to pass a variable through a rails route. I haven't been able to find a case where anyone was doing this with something that wasn't an id of a model. I'm not certain if that's the source of the problem.
In the…
In Ruby 1.9.3, you can do
"\x00\x01".unpack 'S' #=> 1 * 256 + 0 = 256, my machine use little endian by default
"\x00\x01".unpack 'S>' #=> 0 * 256 + 1 = 1
But Ruby 1.8.7 doesn't have the ">" "<" annotation. So in 1.8.7, what is the best way…
I am creating contacts & users in the DB in seed.rb. Using the code below, the contact is saved but the child user is not. What am I missing? I've tried with and without the if statement, and the user is never saved.
Models
class Contact <…
While running bundle install against a "fresh" deployment (e.g. no Gemfile.lock yet) with Ruby 1.8.7 and Rails 3.2.13, bundler appears to be attempting to upgrade to Rails 4! I'm not sure why it is doing this as I have the rails version specifically…
Ruby 1.8.7
array = [[1.5,"cm"],[1.5,"cm"],[1.5,"m"]]
How to compare each array inside the variable array and see if it is equal,
if equal then move on else if not equal then return the index of the array element which was not equal and stop…