method_missing not picking up custom attributes?

57 views
Skip to first unread message

Fireborn Silvaranth

unread,
Feb 14, 2014, 3:41:44 PM2/14/14
to ruby-...@googlegroups.com
Maybe I'm not getting something but I was looking at the method_missing documentation
 
 
(Object) method_missing(m, *args, &block)
 
You can add whatever you want to the locale file, and it will get caught here. E.g., in your locale file, create a
name:
  girls_name: ["Alice", "Cheryl", "Tatiana"]

Then you can call Faker::Name.girls_name and it will act like #first_name

 
I added Faker::Config.locale = :en to environment.rb
 
Added
en:
 company:
  job_title: ["Accountant", "Customer Service Rep", "CEO"]
to en.yml
 
attempted to call Faker::Company.job_title
and get an undefined method 'job_title' error
 
Is this not correct?

Conrad Taylor

unread,
Feb 14, 2014, 4:45:11 PM2/14/14
to ruby-...@googlegroups.com
Fireborn, the method, job_title, needs to be defined on the class, Faker::Company.  Are you working in a fork of the original project?

--
You received this message because you are subscribed to the Google Groups "Ruby Faker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-faker+...@googlegroups.com.
To post to this group, send email to ruby-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ruby-faker.
For more options, visit https://groups.google.com/groups/opt_out.


Think different and code well,

Conrad Taylor

Fireborn Silvaranth

unread,
Feb 15, 2014, 1:06:20 PM2/15/14
to ruby-...@googlegroups.com
I figured this out.

You just need to add faker: above the custom lists in your locale file

In en.yml

en:
faker:


company:
job_title: ["Accountant", "Customer Service Rep", "CEO"]

Now calling Faker::Company.job_title will return one of the list entries.

The documentation was just lacking that one little line.

Reply all
Reply to author
Forward
Message has been deleted
0 new messages