Created
March 16, 2018 09:41
-
-
Save soumyaray/6abd657f401e0fabd03a662e3f089f22 to your computer and use it in GitHub Desktop.
Orison Ruby Q&A
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
# OOP | |
module Scrambler | |
def scramble | |
json_output = to_json | |
json_output.chars.sample(json_output.length).join | |
end | |
end | |
class Student | |
include Scrambler | |
def initialize(fname, lname, id) | |
# initialize "instance variables" | |
@fname = fname | |
@lname = lname | |
@id = id | |
end | |
attr_reader :id | |
attr_accessor :fname, :lname | |
def full_name | |
@lname + ', ' + @fname | |
end | |
def to_json(*options) | |
{ | |
id: @id, | |
full_name: full_name | |
}.to_json(*options) | |
end | |
end | |
class ClassRoom | |
include Scrambler | |
# ... | |
# def to_json | |
end | |
st = Student.new('Orison', 'Flores', 9234) | |
# LAMBDAS (anonymous functions) | |
weird = ->(str) { str.reverse.upcase } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment