Skip to content

Instantly share code, notes, and snippets.

View coolbrg's full-sized avatar

Budh Ram Gurung (BRG) coolbrg

View GitHub Profile
@coolbrg
coolbrg / gist:42056a1fbcbe279bb222
Created June 25, 2014 02:44
Class Method Demo Phase 1
class ClassMethodDemo
def self.greet
puts "Hello, Ruby"
end
end
ClassMethodDemo.greet
@coolbrg
coolbrg / gist:541b1f8d854a2eddd3a9
Created June 25, 2014 02:46
Class Method Demo Phase 2
class ClassMethodDemo
def self.greet
puts "Hello, Ruby"
end
ClassMethodDemo.greet
end
@coolbrg
coolbrg / gist:72e5cae24a3f4fe1b8ba
Created June 25, 2014 02:48
Class Method Phase 3
class ClassMethodDemo
def self.greet
puts "Hello, Ruby"
end
greet
end
@coolbrg
coolbrg / gist:44efd3d4e6072d8b32dc
Created June 25, 2014 02:48
Class Method Demo Phase 4
class ClassMethodDemo
def self.greet
puts "Hello, Ruby"
end
end
class UseDemo < ClassMethodDemo
greet
end
@coolbrg
coolbrg / gist:66e797cffed73275c290
Created June 25, 2014 03:04
Multiple Inheritance Demo
module Aa
def a_foo
puts "A's foo"
end
end
module Bb
def b_foo
puts "B's foo"
end
@coolbrg
coolbrg / gist:c0fd8b3400842915bec7
Created June 25, 2014 03:06
Single Inheritance Demo
class Mammal
def breathe
puts "inhale and exhale"
end
end
class Cat < Mammal
def speak
puts "Meow"
end
class SelfDemo
def foo(val)
@value = val
bar
end
def bar
puts @value
end
end
@coolbrg
coolbrg / gist:80299aa64c1e20f0842c
Created June 25, 2014 03:24
Lambda and Proc Return Behavior
def lambda_test
lam = lambda { return }
lam.call
puts "Hello world"
end
puts "Lambda Test : #{lambda_test }"
def proc_test
proc = Proc.new { return }
@coolbrg
coolbrg / gist:80398b788cf5b02374ca
Created June 25, 2014 04:56
Rails uses open classes
class Fixnum
def hours
self * 3600
end
def from_now
Time.now + self
end
end
@coolbrg
coolbrg / gist:5a182274954ba883587f
Last active August 29, 2015 14:02
Mapping Code for Ruby Metaprogramming Course
RUBY_EXPERIENCE_POINT = 50
# Student Class
class Student
KNOWLEDGE_TARGET = 75 # 75 percentage of cencepts
DEFAULT_EXPERIENCE_PERCENT = 10
attr_accessor :enthusiastic, :class_details
def initialize(ruby_experience, enthusiastic)