Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Consider, however, what would happen if we turned the logic around: What if,
- #instead of an @writable attribute, we had coded @read_only instead? The natural
- #tendency would be to simply throw in a ! or a not:
- def title=( new_title )
- if not @read_only
- @title = new_title
- end
- end
- #The trouble with this if statement is that it is just slightly more verbose than
- #it needs to be. A more concise—and idiomatic—way to say the same thing is:
- def title=( #new_title )
- unless @read_only
- @title = new_title
- end
- end
- #Olsen, Russ (2011). Eloquent Ruby (p. 18). Addison-Wesley Professional. Kindle #Edition.
Add Comment
Please, Sign In to add comment