Skip to content

Instantly share code, notes, and snippets.

View mehdi-farsi's full-sized avatar

Mehdi FARSI mehdi-farsi

View GitHub Profile
class Hash
def to_s
'hash'
end
end
h = {}
p h.to_s # => "hash"
Symbol.all_symbols.length # => 3893
Symbol.all_symbols.grep(/Struct/) # => [:Struct]
:dummy_symbol
Symbol.all_symbols.length # => 3894
Symbol.all_symbols.grep(/dummy_symbol/) # => [:dummy_symbol]
dummy_variable = nil
Symbol.all_symbols.length # => 3895
Symbol.all_symbols.grep(/dummy_variable/) # => [:dummy_variable]
'pending'.object_id # => 70324176174080
'pending'.object_id # => 70324176168090
:pending.object_id # => 1277788
:pending.object_id # => 1277788
module A
autoload(:B, './b.rb')
p constants
end
autoload(:C, './c.rb')
module A
p autoload? :C
end
p autoload? :C
module A
autoload(:B, './b.rb')
p autoload?(:B)
B
p autoload?(:B)
end
module Engine
puts 'The Engine module is loading!'
end
module Car
autoload(:Engine, './engine.rb')
puts "The Engine module isn't yet loaded!"
Engine
puts "The Engine module has been successfully loaded!"
end
class Array
def my_map
return self.dup unless block_given?
ary = []
self.each do |elem|
ary << yield(elem)
end
ary