Yan Pritzker photographer, entrepreneur, software engineer, musician, skier

Blog :: Git Workflows Book :: Dotfiles :: Photography :: About Me

TwitterCounter for @skwp

Get the news feed
Get updates by email
Follow me on twitter

hello, i'm yan

I am a photographer, entrepreneur, software engineer, guitarist, climber, and telemark skier

This blog is about startups, blogging, Ruby On Rails, virtualization and cloud computing, photography, customer service, marketing, ux and design, git, and lots more.

Enterprise intelligence with prediction markets

Find out what your team, colleagues and partners really know about the future — and leverage their knowledge to improve business decisions.

I'm the founder of Planypus, the place to share your plans!

Archives

Contact

Reach me at yan at pritzker.ws

Simple global settings for your Rails app

Posted 17 December 2007 @ 2am | Tagged thoughts


Submit to HN

If you’ve got some global settings and don’t want to bother storing them in the database or YAML, here’s a quick way to get easy dotted notation access to them:

ApplicationSettings = OpenStruct.new(
    :some_variable => true,

    :complex_settings => {
      :one => [:two,:three,:four],

      :foo => {
        :bar => :baz
      }
    }
)

Then you can simply access it via ApplicationSettings.complex_settings.one. Quick & dirty, or quick & clean?


2 Comments

Posted by
George Anderson
19 December 2007 @ 2pm

The dotted notation doesn’t seem to work:

http://pastie.caboo.se/130483

Or am I missing something?


Posted by
Yan
19 December 2007 @ 5pm

Oops! I modified the pastie to reflect changes. I forgot I was using an extension that made all my hashes dot-accessible.

# turn hashes into openstruct-like objects with dotted access
class Hash
def method_missing(meth, *args, &block)
if args.size == 0
self[meth.to_s] || self[meth.to_sym]
end
end
end


Leave a Comment