This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MyModule | |
def self.included(base) | |
puts base | |
base.instance_variable_set :@my_instance_variable, {} | |
base.extend ClassMethods | |
end | |
module ClassMethods | |
def my_instance_variable | |
# self is ClassA here, so we need to call superclass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
recursive_array = lambda do |array, result| | |
array.each do |item| | |
result << item[:name] if item[:name] | |
recursive_array.call(item[:children], result) if item[:children] | |
end | |
result | |
end | |
a = [ | |
{name: "Folder 1", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Gladiator | |
attr_accessor :name, :rank, :height, :weight | |
def initialize | |
yield(self) | |
end | |
end | |
spartak = Gladiator.new do |his| | |
his.name = "spartak" |
NewerOlder