Skip to content

Instantly share code, notes, and snippets.

View irridescentrambler's full-sized avatar
🤓
Exploring

Nikhil Mohadikar irridescentrambler

🤓
Exploring
View GitHub Profile
View Demo.jsx
import { React } from 'react';
import Axios from 'axios';
class Demo extends React.Component{
initialize(){
this.state = {
userInput: nil,
employees: [],
status: nil
}
View method_original_name_demo.rb
class Human
attr_accessor :first_name, :last_name
def initialize(first_name, last_name)
@first_name = first_name
@last_name = last_name
end
def full_name
"#{first_name} #{last_name}"
View source_location_demo_1.rb
[1,2,3,4,5].method(:length).source_location
#=> nil
"Ruby".method(:concat).source_location
#=> nil
class Array
def subset?(sub_array)
sub_array.each do |element|
return false unless self.include?(element)
View source_location_demo.rb
module Configurable
def is_a
wrapper(true)
end
def is_not_a
wrapper(false)
end
private
View owner_demo.rb
require 'active_record'
ActiveRecord::Base.method(:new).owner
#=> ActiveRecord::Inheritance::ClassMethods
ActiveRecord::Base.method(:create).owner
#=> ActiveRecord::Persistence::ClassMethods
ActiveRecord::Base.method(:update).owner
#=> ActiveRecord::Querying
View method_demo.rb
# A simple class in Ruby
class Human
def introduce
"Hi, I am a #{self.class.name}"
end
end
Human.ancestors
#=> [Human, Object, Kernel, BasicObject]
# Object is present in Human class's ancestor tree.
View descendants_demo.rb
class A
end
class B < A
end
class C < B
end
A.descendants
View complex_method_lookup.rb
class Human
def introduce
puts "Hello I am a #{self.class.name}"
end
end
class SuperHuman < Human
include SuperPowers
include Enemies
end
View simple_method_lookup_demo.rb
module SuperPowers
def powers
puts "I can run at 80 mph and lift 200 lbs weight"
end
end
class Human
def introduce
puts "Hi i am a #{self.class.name}"
end
View Ruby Assignment
class Game
def play(matches)
matches.each do |match|
result = match.split(";")
first_team = Team.find_or_initialize(result[0])
second_team = Team.find_or_initialize(result[1])
outcome = result[2]
case outcome
when "win"
first_team.wins!