ruby on rails - When and why class and global variables should be used? -
i using ruby on rails 3.0.7 , know when , why class (@@) , global ($) variables should used , if in this case used.
p.s.: asking question because having mentioned case-problem , in answer proposed use of class variable. grateful can explain me if in case use that.
the short answer is: never.
i'm new ruby, know other languages: global variables never thread-safe.
along same lines, avoid singleton pattern plague unless ever deal unique thread.
edit:
as aside, googling ruby dependency injection suggests ruby doesn't need of it. well, tell what. does.
because assumed doesn't, there mountains of gems , libraries , not out there. assume ever have single thread , io blocking. had not done start, might have been thread safe , non-blocking instead. currently, aren't.
and had done so, have been playing better event-driven servers too.
as things stand, it's bloody mess.
event machine not thread-safe. thin , goliath aren't same token. rack-async monkey patching whole thing. passenger uses fork , smart if install ree/1.8.7 rails. mongrel thread safe io-blocking. webrick single-threaded , io blocking. list goes on. it's messy.
Comments
Post a Comment