Module: Ruff::Standard::State

Defined in:
lib/ruff/standard/state.rb

Overview

State provides effects State.get and State.modify , and the implementation of the mutable cell or so-called state .

The module has an instance of Instance and provides its methods as module method.

Examples:

r = State.with {
  State.put 10
  puts State.get #==> 10
  State.modify {|s| s + 20}
  State.modify {|s|
    puts s #==> 30
    0
  }

  puts State.get #==> 0

  State.put 11
}

puts r #==> 11

See Also:

Defined Under Namespace

Classes: Instance

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#effObject (readonly)



136
137
138
# File 'lib/ruff/standard/state.rb', line 136

def eff
  @eff
end

Class Method Details

.getObject



109
110
111
# File 'lib/ruff/standard/state.rb', line 109

def get
  @inst.get
end

.modify(&fn) ⇒ Object



114
115
116
# File 'lib/ruff/standard/state.rb', line 114

def modify(&fn)
  @inst.modify(&fn)
end

.put(s) ⇒ Object



119
120
121
# File 'lib/ruff/standard/state.rb', line 119

def put(s)
  @inst.put s
end

.with(&task) ⇒ Object



129
130
131
# File 'lib/ruff/standard/state.rb', line 129

def with(&task)
  @inst.with(&task)
end

.with_init(init, &task) ⇒ Object



124
125
126
# File 'lib/ruff/standard/state.rb', line 124

def with_init(init, &task)
  @inst.with_init init, &task
end