skwpspace yan pritzker’s home on the web

skwpspace is Yan Pritzker's home on the web

Blog :: Photography :: About Me

hello, i'm yan

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

Get updates by email
Follow me on twitter

Top Posts

planypus

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

cohesiveft

Accessible, manageable, virtualized application stacks ready to download or deploy to the cloud!

flickr

at the paradeat the parade@slava626@leorazellman and @smazo at bat17my poor ricohyou're wearing my sweaterthe graduatethe answer, my friend

Archives

Contact

Reach me at yan at pritzker.ws

Posted
17 December 2007 @ 2am

Tagged
thoughts

Simple global settings for your Rails app

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

Nightwalkers Pigeon godfather + lieutenant