Module: Shitceptions
- Defined in:
- lib/shitceptions.rb,
lib/shitceptions/error.rb,
lib/shitceptions/version.rb
Defined Under Namespace
Classes: ShittyArgumentError, ShittyEmojiError
Constant Summary collapse
- VERSION =
'1.0.0'
Class Method Summary collapse
-
.config_option(name, default_value) ⇒ Object
Set a config option for the module.
-
.configure {|_self| ... } ⇒ Object
Configure the behavior of Shitceptions.
-
.shittify(klass, emoji_name) ⇒ Object
Add Shitceptions to the given class, with the given emoji.
Class Method Details
.config_option(name, default_value) ⇒ Object
Set a config option for the module. This will define a getter and setter method dynamically.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/shitceptions.rb', line 34 def config_option(name, default_value) normalized_name = name.to_s.downcase.gsub(/[[:space:]]/, '_').to_sym instance_eval " def \#{normalized_name}=(value)\n @\#{normalized_name} = value\n end\n\n def \#{normalized_name}?\n @\#{normalized_name}.nil? ? \#{default_value} : @\#{normalized_name}\n end\n RUBY\nend\n" |
.configure {|_self| ... } ⇒ Object
Configure the behavior of Shitceptions
23 24 25 |
# File 'lib/shitceptions.rb', line 23 def configure(&block) yield(self) end |
.shittify(klass, emoji_name) ⇒ Object
Add Shitceptions to the given class, with the given emoji.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/shitceptions.rb', line 58 def shittify(klass, emoji_name) raise ShittyArgumentError.new(klass) unless klass.kind_of?(Class) emoji = EMOJIS[emoji_name.to_s.downcase.gsub(/[[:space:]]/, '_').to_sym] raise ShittyEmojiError(emoji_name) unless emoji if include_original_error? klass.class_eval " alias_method :unshitty_to_s, :to_s\n\n def to_s\n \"\#{emoji} \\\#{unshitty_to_s}\"\n end\n RUBY\n else\n klass.class_eval <<-RUBY\n alias_method :unshitty_to_s, :to_s\n\n def to_s\n \"\#{emoji} \"\n end\n RUBY\n end\nend\n" |