While I was in my first couple years of college, Python was gaining traction as a hot new programming language. I had been programming in C since high school, but was curious about new languages. I took an interest in learning more about Python. A classmate told me that whitespace (at least indentation) was significant […]
Tag Archives: ruby
Hooking in an LDAP Test Server to Cucumber Tests
I managed to get a custom Devise strategy with LDAP working, but had no clear way of automating tests. I wanted to validate if I still had to keep the password fresh in the database, and needed to be able to write scenarios around that in case someone attempted to refactor out the code. After […]
Ruby Keyword Argument Implementation Differences Between 2.1 and 2.2
I’m currently reading through Ruby Under a Microscope: An Illustrated Guide to Ruby Internals, and when I tried to test the “hidden hash” in ruby 2.2, I got different results from the book. In Ruby 2.2, it appears that the default arguments are used as one expects, without regard to the Hash monkey patch: ### […]
Programming Style: Language Specific Domains
My Beginner and C Days The visual presentation of the code has mattered to me, from the first days I wrote C code in Microsoft editor. In those days, it was a Microsoft C 5.0 IDE on either DOS or OS/2. #include “stdio.h” main() { int rows,columns,ROW, COLUMN; scanf(“%d %d”,&ROW,&COLUMN); rows = 0; columns = […]
Mac OS X Mavericks, rbenv, and ruby-build “Missing the OpenSSL lib?”
openssl version: 1.0.1i, rbenv version: 0.4.0, ruby-build as plugin in the ~/.rbenv/plugins directory. The version of openssl on a Mavericks machine got out of sync with rbenv and ruby-build for some reason. For every attempt at installing a ruby version through rbenv attempted, we got the following message: “The Ruby openssl extension was not compiled. […]
Refinements in Ruby: in map: super: no superclass method
I was trying out refinements to see if they would help clean up some parsing code. I liked defining a couple of methods for the String class to respond to, but really didn’t want them as permanent monkey patches on String. And so, I had a pipe mapping module with refinements: module PipeMapping refine String […]
Serving a file from your Rails app from another server protected by basic authentication
Interesting problem: Retrieve a document from one web service protected by basic auth (or some authentication mechanism) and serve it via a public link on another website. It ended up boiling down to this code in the controller (reduced to be in the same method instead of factored out as it was.) def get_download response […]
Nesting resource routes with alternate scopes and keys + strong parameters.
DISCLAIMER: This is a contrived example translated from a case where it actually made way more sense to break the familiar nested resource pattern. Also, I haven’t double-checked how Rails’ pluralization rules would affect the naming of any given Species. Say you have a pair of models: class Species # id # latin_name_with_underscores end class […]
The convenience of Ruby 2.1 def returning a symbol instead of nil
Prior to 2.1, if you defined a method, you received nil as a return value: irb(main):001:0> def fun irb(main):002:1> end => nil With 2.1, the method definition returns a symbol for the method name: irb(main):001:0> def fun irb(main):002:1> end => :fun One impact of this is that the following pattern for declaring a single private […]
Passing Additional Arguments to FactoryGirl Factories
I wanted to create a factory that would link various states to my model, but from a specified list instead of automatically generated. I discovered that these are transient attributes: FactoryGirl.define do factory :business do name “MyString” # # # trait :with_states do ignore do state_list [] end # add association equal to state code […]