Module: BreezyPDF::Util
- Included in:
- BreezyPDF
- Defined in:
- lib/breezy_pdf/util.rb
Overview
Utility methods
Instance Method Summary collapse
Instance Method Details
#mattr_accessor(*syms, &blk) ⇒ Object
44 45 46 47 |
# File 'lib/breezy_pdf/util.rb', line 44 def mattr_accessor(*syms, &blk) mattr_reader(*syms, &blk) mattr_writer(*syms) end |
#mattr_reader(*syms) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/breezy_pdf/util.rb', line 6 def mattr_reader(*syms) syms.each do |sym| raise NameError, "invalid attribute name: #{sym}" unless /\A[_A-Za-z]\w*\z/.match?(sym) class_eval(" @@\#{sym} = nil unless defined? @@\#{sym}\n def self.\#{sym}\n @@\#{sym}\n end\n EOS\n\n class_eval(<<-EOS, __FILE__, __LINE__ + 1)\n def \#{sym}\n @@\#{sym}\n end\n EOS\n class_variable_set(\"@@\#{sym}\", yield) if block_given?\n end\nend\n", __FILE__, __LINE__ + 1) |
#mattr_writer(*syms) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/breezy_pdf/util.rb', line 25 def mattr_writer(*syms) syms.each do |sym| raise NameError, "invalid attribute name: #{sym}" unless /\A[_A-Za-z]\w*\z/.match?(sym) class_eval(" @@\#{sym} = nil unless defined? @@\#{sym}\n def self.\#{sym}=(obj)\n @@\#{sym} = obj\n end\n EOS\n\n class_eval(<<-EOS, __FILE__, __LINE__ + 1)\n def \#{sym}=(obj)\n @@\#{sym} = obj\n end\n EOS\n send(\"\#{sym}=\", yield) if block_given?\n end\nend\n", __FILE__, __LINE__ + 1) |