Skip to content

Instantly share code, notes, and snippets.

@elcontrastador
Created August 31, 2011 07:35
Show Gist options
  • Save elcontrastador/1183009 to your computer and use it in GitHub Desktop.
Save elcontrastador/1183009 to your computer and use it in GitHub Desktop.
odule Oneif
class UserInfo
# attr_accessor :user_type
def initialize(csv_row,header_hash)
@csv_cols = csv_row.split(',')
@header_hash = header_hash
end
def create_accessors
@header_hash.keys.each do |col_name|
unless col_name =~ /^\w+$/
raise "Imported column name is not valid method name!"
end
define_method(:tyler) {puts "hello!"} #
end
end
# spec output
[oneif-user_info (master)]$ rspec ./
..F
Failures:
1) Oneif::UserInfo initialization should map values from the header_hash to respective accessor methods
Failure/Error: @ui.create_accessors
NoMethodError:
undefined method `define_method' for #<Oneif::UserInfo:0x007fbcc4916350>
# ./lib/oneif/user_info.rb:22:in `block in create_accessors'
# ./lib/oneif/user_info.rb:17:in `each'
# ./lib/oneif/user_info.rb:17:in `create_accessors'
# ./spec/oneif/user_info_spec.rb:9:in `block (3 levels) in <top (required)>'
Finished in 0.00107 seconds
3 examples, 1 failure
Failed examples:
rspec ./spec/oneif/user_info_spec.rb:13 # Oneif::UserInfo initialization should map values from the header_hash to respective accessor methods
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment