Guest User

Untitled

a guest
Oct 18th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #Consider, however, what would happen if we turned the logic around: What if,
  2.  
  3. #instead of an @writable attribute, we had coded @read_only instead? The natural
  4.  
  5. #tendency would be to simply throw in a ! or a not:
  6.  
  7. def title=( new_title )
  8. if not @read_only
  9. @title = new_title
  10.  
  11. end
  12. end
  13.  
  14. #The trouble with this if statement is that it is just slightly more verbose than
  15.  
  16. #it needs to be. A more concise—and idiomatic—way to say the same thing is:
  17.  
  18. def title=( #new_title )
  19. unless @read_only
  20. @title = new_title
  21. end
  22. end
  23.  
  24. #Olsen, Russ (2011). Eloquent Ruby (p. 18). Addison-Wesley Professional. Kindle #Edition.
Add Comment
Please, Sign In to add comment