You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-14Lines changed: 20 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,21 @@
1
-
# Expressive 🧠
1
+
# PortableExpressions 🍱
2
2
3
-
A simple and flexible pure Ruby library for building and evaluating expressions.
3
+
A simple and flexible pure Ruby library for building and evaluating expressions. Expressions can be serialized to and built from JSON strings for portability.
4
4
5
5
## Installation
6
6
7
7
Install the gem and add to the application's Gemfile by executing:
8
8
9
-
`bundle add expressive`
9
+
`bundle add portable_expressions`
10
10
11
11
If bundler is not being used to manage dependencies, install the gem by executing:
12
12
13
-
`gem install expressive`
13
+
`gem install portable_expressions`
14
14
15
15
## Usage
16
16
17
17
> [!IMPORTANT]
18
-
> When using the gem, all references to the models below must be prefixed with `Expressive::`. This is omitted in the README for simplicity.
18
+
> When using the gem, all references to the models below must be prefixed with `PortableExpressions::`. This is omitted in the README for simplicity.
An expression represents 2 or more `operands` that are reduced using a defined `operator`. The `operands` of an `Expression` can be `Scalars`, `Variables`, or other `Expressions`. All `operands` must respond to the symbol (i.e. support the method) defined by the `Expression#operator`.
46
+
An expression represents 2 or more `operands` that are reduced using a defined `operator`. The `operands` of an `Expression` can be `Scalars`, `Variables`, or other `Expressions`. All `operands` must respond to the symbol (i.e. support the method) defined by the `Expression#operator`. Just like `Variables`, `Expressions` have non value until they're evaluated by an `Environment`.
47
47
48
-
And `Expression` can store its result back into the `Environment` by defining an `output`.
48
+
Evaluating an `Expression` does the following:
49
+
1. all `operands` are first evaluated in order
50
+
1. all resulting _values_ are reduced using the symbol defined by the `operator`
51
+
52
+
In this way evaluation is "lazy"; it won't evaluate a `Variable` or `Expression` until the `operand` is about to be used.
53
+
54
+
An `Expression` can store its result back into the `Environment` by defining an `output`.
49
55
50
56
```ruby
51
57
# addition
@@ -70,7 +76,7 @@ environment.variables
70
76
71
77
#### Special `operators`
72
78
73
-
Some operators, like logical `&&` and `||` are not methods in Ruby, so we pass a special string/symbol that Expressive understands.
79
+
Some operators, like logical `&&` and `||` are not methods in Ruby, so we pass a special string/symbol that PortableExpressions understands.
74
80
-`&&` is represented by `:and`
75
81
-`||` is represented by `:or`
76
82
@@ -136,26 +142,26 @@ All models have a **required** `object` key that indicates the type of object.
136
142
137
143
### Building (from JSON)
138
144
139
-
To parse a JSON string, use the `Expressive.from_json` method.
145
+
To parse a JSON string, use the `PortableExpressions.from_json` method.
0 commit comments