Module: Nigilist

Defined in:
lib/nigilist.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(message, *args, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/nigilist.rb', line 4

def method_missing(message, *args, &block)
  method_name = message.to_s

  return false if method_name.end_with?('?')

  if method_name.end_with?('s') && method_name[-2..-1] != 'ss'
    if defined?(Rails)
      ar_relation_klass = method_name.singularize.camelize.safe_constantize
      return ar_relation_klass.none if ar_relation_klass && ar_relation_klass.respond_to?(:none)
    end

    return []
  end

  return nil unless method_name.end_with?('!')

  super
end

Instance Method Details

#respond_to_missing?(message, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
# File 'lib/nigilist.rb', line 23

def respond_to_missing?(message, include_private = false)
  method_name = message.to_s

  method_name.end_with?('?') ||
  (method_name.end_with?('s') && method_name[-2..-1] != 'ss') ||
  !method_name.end_with?('!') ||
    super
end