Skip to content

Instantly share code, notes, and snippets.

class MyDBClass
def initialize(*args)
initer = MysqlInitializer.new(*args)
initer.init!
@database = initer.database
end
end
class MysqlInitializer
def initialize(
--------------------------------------------------------- Fixnum#id2name
fix.id2name -> string or nil
------------------------------------------------------------------------
Returns the name of the object whose symbol id is _fix_. If there
is no symbol in the symbol table with this value, returns +nil+.
+id2name+ has nothing to do with the +Object.id+ method. See also
+Fixnum#to_sym+, +String#intern+, and class +Symbol+.
symbol = :@inst_var #=> :@inst_var
id = symbol.to_i #=> 9818
# Returns the parent feed of this feed item
# Warning, this method may be slow if you have a
# large number of FeedTools::Feed objects. Can't
# use a direct reference to the parent because it plays
# havoc with the garbage collector. Could've used
# a WeakRef object, but really, if there are multiple
# parent feeds, something is going to go wrong, and the
# programmer needs to be notified. A WeakRef
# implementation can't detect this condition.
def feed
class Person
def initialize
register
end
attr_accessor :name
private
def register
>> class Foo; class << self; define_method(:bar) { :baz }; end; end
=> #<Proc:0x00361cf8@(irb):1>
>> Foo.bar
=> :baz
>>
class Foo; end
method_names = [:bar, :baz]
return_value = :quxx
Foo.class_eval do
metaclass = class << self; self; end
metaclass.instance_eval do
method_names.each do |method_name|
(defcustom ruby-use-encoding-map t
"*Use `ruby-encoding-map' to set encoding magic comment if this is non-nil."
:type 'boolean :group 'ruby)
(defun ruby-mode-set-encoding ()
(save-excursion
(widen)
(goto-char (point-min))
(when (re-search-forward "[^\0-\177]" nil t)
(goto-char (point-min))
(let ((coding-system
(coding-system-to-mime-charset
(or coding-system-for-write
buffer-file-coding-system))))
# From this:
a_function({
:foo => :bar,
:baz => :quxx
})
# To this:
a_function({
------------------------------------------------------ Enumerable#detect
enum.detect(ifnone = nil) {| obj | block } => obj or nil
enum.find(ifnone = nil) {| obj | block } => obj or nil
------------------------------------------------------------------------
Passes each entry in _enum_ to _block_. Returns the first for which
_block_ is not +false+. If no object matches, calls _ifnone_ and
returns its result when it is specified, or returns +nil+
(1..10).detect {|i| i % 5 == 0 and i % 7 == 0 } #=> nil
(1..100).detect {|i| i % 5 == 0 and i % 7 == 0 } #=> 35