Create module variables in Ruby

Ruby natively supports class variables in modules, so you can use class variables directly, and not some proxy or pseudo-class-variables: module Site @@name = “StackOverflow” def self.setName(value) @@name = value end def self.name @@name end end Site.name # => “StackOverflow” Site.setName(“Test”) Site.name # => “Test”

What is the difference between up-casting and down-casting with respect to class variable

Upcasting is casting to a supertype, while downcasting is casting to a subtype. Upcasting is always allowed, but downcasting involves a type check and can throw a ClassCastException. In your case, a cast from a Dog to an Animal is an upcast, because a Dog is-a Animal. In general, you can upcast whenever there is … Read more

Is final ill-defined?

A very interesting find. To understand it we need to dig into the Java Language Specification (JLS). The reason is that final only allows one assignment. The default value, however, is no assignment. In fact, every such variable (class variable, instance variable, array component) points to its default value from the beginning, before assignments. The … Read more

Ruby class instance variable vs. class variable

Instance variable on a class: class Parent @things = [] def self.things @things end def things self.class.things end end class Child < Parent @things = [] end Parent.things << :car Child.things << :doll mom = Parent.new dad = Parent.new p Parent.things #=> [:car] p Child.things #=> [:doll] p mom.things #=> [:car] p dad.things #=> [:car] … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)