Skip to content

Instantly share code, notes, and snippets.

Created November 4, 2016 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6a5782c1eee9b5ee694b5885e7764cb5 to your computer and use it in GitHub Desktop.
Save anonymous/6a5782c1eee9b5ee694b5885e7764cb5 to your computer and use it in GitHub Desktop.
Is there good reason for preferring one over the other? My thought was that I might not want to expose the :parser - in that case, would it be correct to mark attr_reader :parser private?
~/D/u/r/analyzing-shakespeare ❯❯❯ gd ⏎ master ⬆ ✭ ✱
diff --git a/lib/macbeth_analyzer.rb b/lib/macbeth_analyzer.rb
index 32b7659..78ac6c4 100644
--- a/lib/macbeth_analyzer.rb
+++ b/lib/macbeth_analyzer.rb
@@ -4,7 +4,7 @@ require_relative 'xml_parser'
require_relative 'printer'
class MacbethAnalyzer
- attr_reader :speaker_line_counts
+ attr_reader :speaker_line_counts, :parser
MACBETH_URL = "http://www.ibiblio.org/xml/examples/shakespeare/macbeth.xml"
IGNORE_SPEAKERS = %w(ALL)
@@ -16,7 +16,7 @@ class MacbethAnalyzer
def analyze_speaker_line_counts
speaker_line_counts = Hash.new(0)
- speakers = @parser.parse(query: '//SPEAKER')
+ speakers = parser.parse(query: '//SPEAKER')
speakers.map do |speaker|
unless IGNORE_SPEAKERS.include? speaker.text
speaker_line_counts[speaker.text] += @parser.parse(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment