#apache #archlinux #asterisk #centos #debian #gentoo #haskell #kde #kubuntu #lisp #math #mysql #perl #python #ruby-lang #rubyonrails #suse #ubuntu #vim #wikipedia 0 1 2 3 4 5 6 7 8 9 10 11 12 13
Top Prev 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 Next
#rubyonrails
<smtlaissezfaire> and :symbol.object_id == :symbol.object_id
<tavilach> ok smt i think i get that
<tavilach> so a symbol
<tavilach> = one object
<eshear> that's true, every reference to a symbol is a reference to the same object
<smtlaissezfaire> tavilach - it's also nice for passing "pseudo" constants around. Why would want to pass a method name as a string?
<eshear> psuedo constants == names
<smtlaissezfaire> It could get changed by something else in the process, inadvertantly. It won't have the same object_id, so you won't even be able to check if it's the same after being passed through a few methods, etc.
<tavilach> mk
<nad1m> think of it like your name, you dont want it to be mutable, and every time you use it you want it to refer to the same entity
<ReinH> tavilach: they're interused in rails for two reasons
<smtlaissezfaire> That was another thing that was confusing when I started rails. The agile ruby book had one tiny little paragraph about symbols and I saw them in rails everywhere!
<ReinH> The first is that many rails methods use a method called stringify_keys
<tavilach> which does?
<ReinH> The second is that session, params, and flash are actually instances of HashWithIndifferentAccess, a subclass of Hash in rails that treats params[:foo] and params["foo"] the same
<ReinH> tavilach: stringify_keys turns the keys of a hash into strings
<technoweenie> ReinH: the real reason is textmate changes symbols to a purty color, so we like to use them a lot :)
<eshear> lol
<ReinH> technoweenie: yes, I was about to say :)
<eshear> right, that's the main difference
<smtlaissezfaire> ha!
<ReinH> he's pretty much right.
<nad1m> anyone work through all the exercises in the agile book 2nd ed?
<technoweenie> nah it just makes more sense i think
<ReinH> technoweenie: yes, I think so too
<technoweenie> rather than creating alots of strings each request params['foo'] and params['bar']
<ReinH> strings are like labels
<ReinH> er, symbols that is
<wilfordbrimley> how do i turn a string into constant, that I can call .new on?
<technoweenie> the reason session/params can't be created from a symbolized hash though is it's a potential DOS issue. symbols don't get GCed
<ReinH> symbols are like labels, sort of like pointers
<technoweenie> wilfordbrimley!!
<technoweenie> constantize
<ReinH> wilfordbrimley: constantize
<wilfordbrimley> technoweenie: awesome. thanks!
<ReinH> technoweenie: oic
<technoweenie> anytime for this dude http://en.wikipedia.org/wiki/Image:Noa_briqualon.jpg
<wilfordbrimley> hahahaha
<smtlaissezfaire> is that a rails method or a ruby method?
<wilfordbrimley> that is one grizzled gentleman
<technoweenie> constantize is a rails string inflector
<ReinH> like smtlaissezfaire said, each symbol is unique, and every time you use the same symbol you are referencing one object. Every string is a different object
<technoweenie> you can use const_get though
<technoweenie> Object.const_get("Foo").const_get("Bar") #=> Foo::Bar
<smtlaissezfaire> does it call instance_eval on the string?
<technoweenie> hey ReinH i'm probably going to hop on GoW at around 8ish
<ReinH> smtlaissezfaire: no, it goes through const_get. instance_eval isn't as safe
<ReinH> technoweenie: bah, I'm going to be deploying tonight, so no gears for me
<technoweenie> you guys should check the source before you make assumptions
<ReinH> technoweenie: bastard
Previous Page Next Page