Sha256: dfbb88a949cb3d697994883b77cf6ffe83ac46297e26f57bcb49a5b2380ab9bc

Contents?: true

Size: 615 Bytes

Versions: 8

Compression:

Stored size: 615 Bytes

Contents

class Object
  def meta_def(m,&b) #:nodoc:
    (class<<self;self end).send(:define_method,m,&b)
  end
end

class Regexp
  def number_of_captures #:nodoc:
    c, x = 0, self.source.dup.gsub( /\\\(/, "" ).gsub( /\\\)/, "" )
    while( r = /(\([^\)]*\))/.match( x ) )
      c, x = c+1, r.post_match
    end
    c
  end
  
  # From http://facets.rubyforge.org/apidoc/api/core/classes/Regexp.html
  def arity #:nodoc:
    self.source.scan( /(?!\\)[(](?!\?[#=:!>-imx])/ ).length
  end
end

class Hash
  def keys_to_sym #:nodoc:
    self.each do |k, v|
      self.delete(k)
      self[k.to_s.to_sym] = v
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
Capcode-0.9.8 lib/capcode/core_ext.rb
Capcode-0.9.7 lib/capcode/core_ext.rb
Capcode-0.9.6 lib/capcode/core_ext.rb
Capcode-0.9.5 lib/capcode/core_ext.rb
Capcode-0.9.4 lib/capcode/core_ext.rb
Capcode-0.9.3 lib/capcode/core_ext.rb
Capcode-0.9.2 lib/capcode/core_ext.rb
Capcode-0.9.1 lib/capcode/core_ext.rb