Guest User

Untitled

a guest
Feb 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. # Sometimes :symbol.operator looks nice.
  2. # I generally hate "global variables programming",
  3. # but this extension seems to be safe and handy.
  4. def experimental_by_oleganza
  5. # arrays for OR, hashes for AND with in-Symbol operators
  6. all([{:name => ["john", "jane"]}, {:age.gr => 3, :age.lt => 65}])
  7.  
  8. # same as above, but with optional :any, :all keys (:any for OR, :all for AND)
  9. all([{:name => ["john", "jane"]}, {:any => [{:age.gt => 3}, {:parental_control.not => :nil}], :age.lt => 65}])
  10.  
  11. # minimalistic hashes with :all, :any quantors
  12. all(:any => {
  13. :name => ["john", "jane"],
  14. :all => {
  15. :any => {
  16. :age.gt => 3,
  17. :parental_control.not => :nil
  18. },
  19. :age.lt => 65
  20. }
  21. }
  22. )
  23.  
  24. # ParseTree/RubyToRuby version
  25. all { |p|
  26. ["john", "jane"].include?(p.name) or
  27. (
  28. (p.age > 3 or p.parental_control != nil) and
  29. p.age < 65
  30. )
  31. }
  32.  
  33. # Maybe we should adopt every flavor to be detected automatically.
  34. # Also, it is a good idea to construct proc's from the AST for in-memory operations
  35.  
  36. end
Add Comment
Please, Sign In to add comment