Rails white-labeling file

Currently, I have my white-label code in config/application.yml (this file was generated from the figaro gem). Initially, I added it here because I could use the ENV variables in the app and it seemed to work well for white-labelling purposes. appl...
more »

2017-01-16 19:01 (0) Answers

eval and Binding in ruby

I want to access the variable and method defined in top level main object in the program @x = :hello def instanceMethodMain p "instanceMethodMain" end class Baz def method p eval("@x", TOPLEVEL_BINDING) p eval("instanceMethodMain", ...
more »

2017-01-16 14:01 (2) Answers

How to install the Nokogiri gem using Ruby 1.9.3

I'm using Ruby 1.9.3 with my Rails v3.2.19 application and I'm unable to run bundle because Nokogiri requires a Ruby version >= 2.1.0. At the moment I cannot upgrade my Ruby version and I really need to install Nokogiri otherwise my app won't run. B...
more »

2017-01-16 12:01 (1) Answers

create object a random number of times ruby

def pass_growing_season self.age += 1 if self.age >= 6 harvested_oranges << Orange.new #NEED 100 - 300 !!! end if self.height < 25 self.height += 2.5 end end I am trying to initialize an Orange class that is defined in anot...
more »

2017-01-15 21:01 (2) Answers

Importing Wordpress Posts - Getting Load Error

I was trying to import wordpress posts to my new jekyll site using these instructions: import.jekyllrb.com/docs/wordpress But when I follow those instructions including sucessfully installing "gem install unidecode sequel mysql2 htmlentities" into /L...
more »

2017-01-15 00:01 (1) Answers

Naming Ruby methods

Given a class: class Shell attr_reader :spiral def initialize spiral @spiral = spiral end def ????? # do stuff... end end some_shell = Shell.new([[1,2],[4,3]) some_shell.spiral #=> [[1,2], # [4,3]] some_sh...
more »

2017-01-14 22:01 (5) Answers

Enumerator block execution order in Ruby

In David Black's The Well-Grounded Rubyist I came across the following Ruby code about enumerators: e = Enumerator.new do |y| puts "Starting up the block!" (1..3).each {|i| y << i } puts "Exiting the block!" end p e.to_a which ...
more »

2017-01-14 19:01 (4) Answers

Why is Range#sum defined in Enumerable module?

In Ruby 2.4 and for Integer Ranges, Range(Enumerable)#sum is optimized to return a result directly, without iterating over all elements. I don't understand why the corresponding code is defined in enum.c for the Enumerable module and not in range.c...
more »

2017-01-13 15:01 (1) Answers

Rails Rspec integer equals string ("1" == 1)

How, in rspec, do you compare the value of something while ignoring the type? Failure/Error: expect(variable).to eql model.id expected: 1234 got: "1234" (compared using eql?) I've tried eq (which compares using ==) and eql (which comp...
more »

2017-01-13 11:01 (2) Answers

What are the conventions for types in Ruby?

Being that Ruby is a language with purely dynamic types, I'm never quite sure what level of expectation I should have for the types passed to my methods. For example, if my method only functions when passed an Integer, should I be actively checking t...
more »

2017-01-12 17:01 (4) Answers

Dir.exist? does not work as expected

I have an issue while checking if a directory exists. I'm writing a small Ruby app that performs a svn checkout from a repository, and then looks in the working copy to see if a certain directory exists. I have a SVNClient class that performs the...
more »

2017-01-12 15:01 (1) Answers

Nested Loop: to be dynamic?

Ok i'm actually doing this exercise to tackle those nested loop questions. I would say this would be the hardest one for me. I tried my best to be more dynamic instead of static. Can anyone give me tips on how to solve this? expected output: 1 1 2 ...
more »

2017-01-12 13:01 (2) Answers