Skip to content

Instantly share code, notes, and snippets.

@AndrewVos
Created December 19, 2011 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewVos/1499406 to your computer and use it in GitHub Desktop.
Save AndrewVos/1499406 to your computer and use it in GitHub Desktop.
class Object
def path path
object = self
path.split(
path.split("/").each do |part|
if object.respond_to? part.to_sym
object = object.send(part.to_sym)
else
return nil
end
end
object
end
end
require "ostruct"
item = OpenStruct.new
item.meh = OpenStruct.new
item.meh.bleh = OpenStruct.new
item.meh.bleh.hello = "That\'s the way AHAH AHAH"
p item.path("meh/bleh/hello")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment