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
Show hidden characters
{ | |
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and | |
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope | |
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is | |
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are: | |
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. | |
// Placeholders with the same ids are connected. | |
// Example: | |
// "Print to console": { | |
// "scope": "javascript,typescript", |
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 Field(object): | |
def __init__(self, name): | |
self._name = name | |
def __get__(self, instance, owner): | |
return instance._data[self._name] | |
def __set__(self, instance, value): | |
instance._data[self._name] = value |
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
# lib/part_3/advanced_credit_score.rb | |
require_relative 'advanced_consumer' | |
class AdvancedCreditScore | |
def self.simulate(&block) | |
consumer = AdvancedConsumer.new | |
# TODO Part 3 | |
# Once again, use instance eval to invoke the block on the consumer |
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
# lib/part_2/customer.rb | |
class Customer | |
attr_accessor :balance | |
def good_standing? | |
balance >= 0 | |
end | |
end |
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
# lib/part_2/credit_score.rb | |
require_relative 'consumer' | |
module CreditScore | |
def self.simulate(&block) | |
consumer = Consumer.new | |
consumer.instance_eval(&block) | |
consumer.score | |
end | |
end |
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
datasource.methods.grep(/^get_(.*)_value/) { Customer.has_field $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 Customer | |
attr_reader :id, :datasource | |
def initialize(id, datasource) | |
@id = id | |
@datasource = datasource | |
end | |
def respond_to?(method) | |
datasource.respond_to?("get_#{method}_value") || super |
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 Customer | |
attr_reader :id, :datasource | |
def initialize(id, datasource) | |
@id = id | |
@datasource = datasource | |
end | |
def method_missing(methodname, *args, &block) | |
super unless @datasource.respond_to? "get_#{methodname}_value" |
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 Customer | |
attr_reader :id, :datasource | |
def initialize(id, datasource) | |
@id = id | |
@datasource = datasource | |
@datasource.methods.grep(/^get_(.*)_value/) { Customer.has_field $1 } | |
end | |
def self.has_field(fieldname) |
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 Customer | |
attr_reader :id, :datasource | |
def initialize(id, datasource) | |
@id = id | |
@datasource = datasource | |
end | |
def self.has_field(fieldname) | |
define_method fieldname do |
NewerOlder