0.0
No commit activity in last 3 years
No release in over 3 years
This is a simple Ruby module for detecting variable changes inside a block for improving code with increased idempotency.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.0
>= 1.6.4
>= 0
 Project Readme

Block Changes

Build Status Dependency Status

Detecting changes in a Ruby block

The following example illustrates how to see if changes are detected in a Ruby block for the expected variables. Variables a, b, c are concerned in this example. If these variables are changed changes_detected? will return true. If these variables are not changes in the block changes_detected? will return false. This will be helpful to maintain idempotency. The following example is very simple. We'll know what variables we concern about when we write the code so passing those variables to the code will not be hard. Also we might not want to detect changes of local temporary variables defined inside the block.

require 'block_changes'

include BlockChanges

a = 1
b = 2
c = 3

# Note that the variable names are in quotes and it is required.
detect_changes('a', 'b', 'c') do
  a = 2
  b = 3
  c = 4
end

# Check if changes are detected in the block
puts "Changes Detected" if changes_detected?

# Check the number variables changed in the block
puts "No of changes: #{get_changes}"