Skip to content

Commit

Permalink
more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
omkarmoghe committed Mar 25, 2024
1 parent 4dce696 commit f159105
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ variable_b = Variable.new("variable_b")
environment = Environment.new(
"variable_a" => 1
)
env.evaluate(variable_a) #=> 1
env.evaluate(variable_b) #=> MissingVariableError
environment.evaluate(variable_a) #=> 1
environment.evaluate(variable_b) #=> MissingVariableError
```

### Expression
Expand All @@ -60,11 +60,11 @@ storing_output = Expression.new(:+, Scalar.new(1), Scalar.new(2), output: "one_p
environment = Environment.new(
"variable_a" => 2
)
env.evaluate(addition) #=> 3
env.evaluate(multiplication) #=> 4
env.evaluate(storing_output) #=> 3
environment.evaluate(addition) #=> 3
environment.evaluate(multiplication) #=> 4
environment.evaluate(storing_output) #=> 3

env.variables
environment.variables
#=> { "variable_a" => 2, "one_plus_two" => 3 }
```

Expand Down Expand Up @@ -183,6 +183,20 @@ Environment.new(
#=> true
```

#### String manipulation

```ruby
# Define a reusable `Expression` using `Variables`.
repeat_count = Variable.new("repeat")
string_to_repeat = Variable.new("user_input")
repeater = Expression.new(:*, string_to_repeat, repeat_count)

# E.g. inputs via an `ActionController` (Ruby on Rails)
# GET /repeater?repeat=3&user_input=cool
environment = Environment.new(**params)
environment.evaluate(repeater) #=> "coolcoolcool"
```

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
Expand Down

0 comments on commit f159105

Please sign in to comment.