Class: Object

Inherits:
BasicObject
Defined in:
lib/sinarey_support/core_ext/object/try.rb,
lib/sinarey_support/core_ext/object/blank.rb,
lib/sinarey_support/core_ext/object/to_param.rb,
lib/sinarey_support/core_ext/object/to_query.rb,
lib/sinarey_support/core_ext/object/acts_like.rb,
lib/sinarey_support/core_ext/string/output_safety.rb

Instance Method Summary collapse

Instance Method Details

#acts_like?(duck) ⇒ Boolean

Returns:

  • (Boolean)


2
3
4
# File 'lib/sinarey_support/core_ext/object/acts_like.rb', line 2

def acts_like?(duck)
  respond_to? :"acts_like_#{duck}?"
end

#blank?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/sinarey_support/core_ext/object/blank.rb', line 4

def blank?
  respond_to?(:empty?) ? empty? : !self
end

#html_safe?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/sinarey_support/core_ext/string/output_safety.rb', line 40

def html_safe?
  false
end

#presenceObject



12
13
14
# File 'lib/sinarey_support/core_ext/object/blank.rb', line 12

def presence
  self if present?
end

#present?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/sinarey_support/core_ext/object/blank.rb', line 8

def present?
  !blank?
end

#to_paramObject



2
3
4
# File 'lib/sinarey_support/core_ext/object/to_param.rb', line 2

def to_param
  to_s
end

#to_query(key) ⇒ Object



4
5
6
7
# File 'lib/sinarey_support/core_ext/object/to_query.rb', line 4

def to_query(key)
  require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
  "#{CGI.escape(key.to_param)}=#{CGI.escape(to_param.to_s)}"
end

#try(*a, &b) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/sinarey_support/core_ext/object/try.rb', line 2

def try(*a, &b)
  if a.empty? && block_given?
    yield self
  else
    public_send(*a, &b) if respond_to?(a.first)
  end
end

#try!(*a, &b) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/sinarey_support/core_ext/object/try.rb', line 10

def try!(*a, &b)
  if a.empty? && block_given?
    yield self
  else
    public_send(*a, &b)
  end
end