Skip to content

Instantly share code, notes, and snippets.

@btm
Created September 30, 2013 17:59

Revisions

  1. btm created this gist Sep 30, 2013.
    40 changes: 40 additions & 0 deletions cvar.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    class A
    @@cvar = {}

    def mutate
    @@cvar[:foo] = "bar"
    end

    def add(k,v)
    @@cvar[k] = v
    end

    def show
    p @@cvar
    end
    end

    a = A.new
    a.mutate
    p "before:"
    a.show
    a.add("yellow","elephant")

    a.show

    class A
    @@cvar = {}

    def mutate
    @@cvar[:baz] = "qux"
    end

    def show
    p @@cvar
    end
    end

    a = A.new
    a.mutate
    p "after:"
    a.show
    5 changes: 5 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    "before:"
    {:foo=>"bar"}
    {:foo=>"bar", "yellow"=>"elephant"}
    "after:"
    {:baz=>"qux"}