Referential transparency means replacing an expression with its resulting value without changing program behavior. A referentially transparent expression produces the same result for the same inputs and does not alter the receiver or arguments. section 16.1.2
Replacing expressions with values
Ruby can evaluate `3 + 4` as `7`; because `+` does not modify either operand, replacing `3 + 4` with `7` preserves the program's behavior. Likewise, `map` transforms `[3, 5, 7, 9]` into a new array, `[15, 25, 35, 45]`, without changing its receiver. section 16.1.2
Contrast transparent expressions with state-changing operations:
- Assigning `num = num + 1` changes a variable's binding; creating `new_num = num + 1` preserves the original value and better matches the mathematical model. section 16.1
- `upcase` returns a changed string without modifying the receiver, whereas `upcase!`, `<<`, and `delete` alter existing state. section 16.1.3
- Transparent methods support predictable chains such as `"joe".upcase.reverse`; chaining becomes risky when methods include side effects. section 16.3.2
Referential transparency is a central property of pure functions and contributes to terse, predictable functional code. Ruby supports these techniques but does not guarantee referential transparency or immutability, so programs may combine functional and object-oriented styles. section 16.5 section 16.0








