SlideShare une entreprise Scribd logo
1  sur  110
Télécharger pour lire hors ligne
Ruby’s

case Statement
by Tim Moore
Ruby’s Magical

case Statement
by Tim Moore
Magical
There is Totally
Such a Thing as Magic
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301
handle_redirect(http_response)
when 302
handle_redirect(http_response)
when 303
handle_redirect(http_response)
when 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301
handle_redirect(http_response)
when 302
handle_redirect(http_response)
when 303
handle_redirect(http_response)
when 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301
handle_redirect(http_response)
when 302
handle_redirect(http_response)
when 303
handle_redirect(http_response)
when 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301
handle_redirect(http_response)
when 302
handle_redirect(http_response)
when 303
handle_redirect(http_response)
when 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301
handle_redirect(http_response)
when 302
handle_redirect(http_response)
when 303
handle_redirect(http_response)
when 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301
handle_redirect(http_response)
when 302
handle_redirect(http_response)
when 303
handle_redirect(http_response)
when 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301
handle_redirect(http_response)
when 302
handle_redirect(http_response)
when 303
handle_redirect(http_response)
when 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301
handle_redirect(http_response)
when 302
handle_redirect(http_response)
when 303
handle_redirect(http_response)
when 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301
handle_redirect(http_response)
when 302
handle_redirect(http_response)
when 303
handle_redirect(http_response)
when 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301
handle_redirect(http_response)
when 302
handle_redirect(http_response)
when 303
handle_redirect(http_response)
when 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301
handle_redirect(http_response)
when 302
handle_redirect(http_response)
when 303
handle_redirect(http_response)
when 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301
handle_redirect(http_response)
when 302
handle_redirect(http_response)
when 303
handle_redirect(http_response)
when 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301
handle_redirect(http_response)
when 302
handle_redirect(http_response)
when 303
handle_redirect(http_response)
when 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301
handle_redirect(http_response)
when 302
handle_redirect(http_response)
when 303
handle_redirect(http_response)
when 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301
handle_redirect(http_response)
when 302
handle_redirect(http_response)
when 303
handle_redirect(http_response)
when 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301
handle_redirect(http_response)
when 302
handle_redirect(http_response)
when 303
handle_redirect(http_response)
when 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301
handle_redirect(http_response)
when 302
handle_redirect(http_response)
when 303
handle_redirect(http_response)
when 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301
handle_redirect(http_response)
when 302
handle_redirect(http_response)
when 303
handle_redirect(http_response)
when 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301, 302, 303, 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301, 302, 303, 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
else
handle_unknown_error(http_response)
end
end
def handle_response(http_response)
case http_response.status
when 200
handle_success(http_response)
when 301, 302, 303, 307
handle_redirect(http_response)
when 404
handle_not_found(http_response)
when 400...500
handle_client_error(http_response)
when 500...600
handle_server_error(http_response)
else
handle_unknown_error(http_response)
end
end
def nickname(first_name)
case first_name
when 'Abraham'
nickname = 'Abe'
when 'Abigail'
nickname = 'Abby'
when 'Christopher',
'Christian',
'Christina'
nickname = 'Chris'
# etc., etc.
else
nickname = first_name
end
nickname
end
def nickname(first_name)
case first_name
when 'Abraham'
nickname = 'Abe'
when 'Abigail'
nickname = 'Abby'
when 'Christopher',
'Christian',
'Christina'
nickname = 'Chris'
# etc., etc.
else
nickname = first_name
end
nickname
end
def nickname(first_name)
case first_name
when 'Abraham'
nickname = 'Abe'
when 'Abigail'
nickname = 'Abby'
when 'Christopher',
'Christian',
'Christina'
nickname = 'Chris'
# etc., etc.
else
nickname = first_name
end
nickname
end
def nickname(first_name)
case first_name
when 'Abraham'
nickname = 'Abe'
when 'Abigail'
nickname = 'Abby'
when 'Christopher',
'Christian',
'Christina'
nickname = 'Chris'
# etc., etc.
else
nickname = first_name
end
nickname
end
def nickname(first_name)
case first_name
when 'Abraham'
nickname = 'Abe'
when 'Abigail'
nickname = 'Abby'
when 'Christopher',
'Christian',
'Christina'
nickname = 'Chris'
# etc., etc.
else
nickname = first_name
end
nickname
end
def nickname(first_name)
case first_name
when 'Abraham'
nickname = 'Abe'
when 'Abigail'
nickname = 'Abby'
when 'Christopher',
'Christian',
'Christina'
nickname = 'Chris'
# etc., etc.
else
nickname = first_name
end
nickname
end
def nickname(first_name)
case first_name
when 'Abraham'
nickname = 'Abe'
when 'Abigail'
nickname = 'Abby'
when 'Christopher',
'Christian',
'Christina'
nickname = 'Chris'
# etc., etc.
else
nickname = first_name
end
nickname
end
def nickname(first_name)
case first_name
when 'Abraham'
nickname = 'Abe'
when 'Abigail'
nickname = 'Abby'
when 'Christopher',
'Christian',
'Christina'
nickname = 'Chris'
# etc., etc.
else
nickname = first_name
end
nickname
end
def nickname(first_name)
case first_name
when 'Abraham'
nickname = 'Abe'
when 'Abigail'
nickname = 'Abby'
when 'Christopher',
'Christian',
'Christina'
nickname = 'Chris'
# etc., etc.
else
nickname = first_name
end
nickname
end
def nickname(first_name)
case first_name
when 'Abraham'
nickname = 'Abe'
when 'Abigail'
nickname = 'Abby'
when 'Christopher',
'Christian',
'Christina'
nickname = 'Chris'
# etc., etc.
else
nickname = first_name
end
nickname
end
def nickname(first_name)
case first_name
when 'Abraham'
nickname = 'Abe'
when 'Abigail'
nickname = 'Abby'
when 'Christopher',
'Christian',
'Christina'
nickname = 'Chris'
# etc., etc.
else
nickname = first_name
end
nickname
end
def nickname(first_name)
case first_name
when 'Abraham'
nickname = 'Abe'
when 'Abigail'
nickname = 'Abby'
when 'Christopher',
'Christian',
'Christina'
nickname = 'Chris'
# etc., etc.
else
nickname = first_name
end
nickname
end
def nickname(first_name)
case first_name
when 'Abraham'
nickname = 'Abe'
when 'Abigail'
nickname = 'Abby'
when 'Christopher',
'Christian',
'Christina'
nickname = 'Chris'
# etc., etc.
else
nickname = first_name
end
nickname
end
irb> nickname 'Christopher'
=> "Chris"
irb> nickname 'Abigail'
=> "Abby"
irb> nickname 'Christina'
=> "Chris"
irb> nickname 'Fabio'
=> "Fabio"
def nickname(first_name)
case first_name
when 'Abraham'
nickname = 'Abe'
when 'Abigail'
nickname = 'Abby'
when 'Christopher',
'Christian',
'Christina'
nickname = 'Chris'
# etc., etc.
else
nickname = first_name
end
nickname
end
def nickname(first_name)
case first_name
when 'Abraham'
nickname = 'Abe'
when 'Abigail'
nickname = 'Abby'
when 'Christopher',
'Christian',
'Christina'
nickname = 'Chris'
# etc., etc.
else
nickname = first_name
end
nickname
end
def nickname(first_name)
nickname = case first_name
when 'Abraham'
'Abe'
when 'Abigail'
'Abby'
when 'Christopher',
'Christian',
'Christina'
'Chris'
# etc., etc.
else
first_name
end
nickname
end
def nickname(first_name)
nickname = case first_name
when 'Abraham'
'Abe'
when 'Abigail'
'Abby'
when 'Christopher',
'Christian',
'Christina'
'Chris'
# etc., etc.
else
first_name
end
nickname
end
def nickname(first_name)
case first_name
when 'Abraham'
'Abe'
when 'Abigail'
'Abby'
when 'Christopher',
'Christian',
'Christina'
'Chris'
# etc., etc.
else
first_name
end
!
end
class Color <
Struct.new(:r,:g,:b)
!
RED = Color.new(
0xFF, 0x00, 0x00
)
GREEN = Color.new(
0x00, 0xFF, 0x00
)
BLUE = Color.new(
0x00, 0x00, 0xFF
)
CYAN = Color.new(
0x00, 0xFF, 0xFF
)
MAGENTA = Color.new(
0xFF, 0x00, 0xFF
)
YELLOW = Color.new(
0xFF, 0xFF, 0x00
)
!
end
def primary?(color, mode)
case color
when Color::RED,
Color::GREEN,
Color::BLUE
mode == :additive
when Color::CYAN,
Color::MAGENTA,
Color::YELLOW
mode == :subtractive
else
false
end
end
class Color <
Struct.new(:r,:g,:b)
!
RED = Color.new(
0xFF, 0x00, 0x00
)
GREEN = Color.new(
0x00, 0xFF, 0x00
)
BLUE = Color.new(
0x00, 0x00, 0xFF
)
CYAN = Color.new(
0x00, 0xFF, 0xFF
)
MAGENTA = Color.new(
0xFF, 0x00, 0xFF
)
YELLOW = Color.new(
0xFF, 0xFF, 0x00
)
!
end
def primary?(color, mode)
case color
when Color::RED,
Color::GREEN,
Color::BLUE
mode == :additive
when Color::CYAN,
Color::MAGENTA,
Color::YELLOW
mode == :subtractive
else
false
end
end
irb> primary? Color::RED, :additive
=> true
irb> primary? Color::RED, :subtractive
=> false
irb> primary? Color::CYAN, :subtractive
=> true
irb> primary? Color.new(0,0,255), :additive
=> true
irb> primary? Color.new(0,127,255), :additive
=> false
def local_search(query)
case query
when String
specs_by_name(query)
when Gem::Dependency
search_by_dependency(query)
when Gem::Specification,
RemoteSpecification,
LazySpecification,
EndpointSpecification
search_by_spec(query)
else
raise "You can't search for #{query}."
end
end
def local_search(query)
case query
when String
specs_by_name(query)
when Gem::Dependency
search_by_dependency(query)
when Gem::Specification,
RemoteSpecification,
LazySpecification,
EndpointSpecification
search_by_spec(query)
else
raise "You can't search for #{query}."
end
end
def local_search(query)
case query
when String
specs_by_name(query)
when Gem::Dependency
search_by_dependency(query)
when Gem::Specification,
RemoteSpecification,
LazySpecification,
EndpointSpecification
search_by_spec(query)
else
raise "You can't search for #{query}."
end
end
def local_search(query)
case query
when String
specs_by_name(query)
when Gem::Dependency
search_by_dependency(query)
when Gem::Specification,
RemoteSpecification,
LazySpecification,
EndpointSpecification
search_by_spec(query)
else
raise "You can't search for #{query}."
end
end
def local_search(query)
case query
when String
specs_by_name(query)
when Gem::Dependency
search_by_dependency(query)
when Gem::Specification,
RemoteSpecification,
LazySpecification,
EndpointSpecification
search_by_spec(query)
else
raise "You can't search for #{query}."
end
end
def local_search(query)
case query
when String
specs_by_name(query)
when Gem::Dependency
search_by_dependency(query)
when Gem::Specification,
RemoteSpecification,
LazySpecification,
EndpointSpecification
search_by_spec(query)
else
raise "You can't search for #{query}."
end
end
def local_search(query)
case query
when String
specs_by_name(query)
when Gem::Dependency
search_by_dependency(query)
when Gem::Specification,
RemoteSpecification,
LazySpecification,
EndpointSpecification
search_by_spec(query)
else
raise "You can't search for #{query}."
end
end
def local_search(query)
case query
when String
specs_by_name(query)
when Gem::Dependency
search_by_dependency(query)
when Gem::Specification,
RemoteSpecification,
LazySpecification,
EndpointSpecification
search_by_spec(query)
else
raise "You can't search for #{query}."
end
end
def local_search(query)
case query
when String
specs_by_name(query)
when Gem::Dependency
search_by_dependency(query)
when Gem::Specification,
RemoteSpecification,
LazySpecification,
EndpointSpecification
search_by_spec(query)
else
raise "You can't search for #{query}."
end
end
def local_search(query)
case query
when String
specs_by_name(query)
when Gem::Dependency
search_by_dependency(query)
when Gem::Specification,
RemoteSpecification,
LazySpecification,
EndpointSpecification
search_by_spec(query)
else
raise "You can't search for #{query}."
end
end
def want_a_beer?(beer_type)
case beer_type
when /^Sierra Nevada|IPA/
:yes
when /V(ictoria)? ?B(itter)?/,
/Bud(weiser)?/
:no
else
:probably
end
end
def want_a_beer?(beer_type)
case beer_type
when /^Sierra Nevada|IPA/
:yes
when /V(ictoria)? ?B(itter)?/,
/Bud(weiser)?/
:no
else
:probably
end
end
def want_a_beer?(beer_type)
case beer_type
when /^Sierra Nevada|IPA/
:yes
when /V(ictoria)? ?B(itter)?/,
/Bud(weiser)?/
:no
else
:probably
end
end
def want_a_beer?(beer_type)
case beer_type
when /^Sierra Nevada|IPA/
:yes
when /V(ictoria)? ?B(itter)?/,
/Bud(weiser)?/
:no
else
:probably
end
end
def want_a_beer?(beer_type)
case beer_type
when /^Sierra Nevada|IPA/
:yes
when /V(ictoria)? ?B(itter)?/,
/Bud(weiser)?/
:no
else
:probably
end
end
irb> want_a_beer? 'Sierra Nevada Pale Ale'
=> :yes
irb> want_a_beer? 'Sierra Nevada Torpedo IPA'
=> :yes
irb> want_a_beer? 'Mountain Goat IPA'
=> :yes
irb> want_a_beer? 'Victoria Bitter'
=> :no
irb> want_a_beer? 'VB'
=> :no
irb> want_a_beer? 'V Bitter'
=> :no
irb> want_a_beer? 'Budweiser'
=> :no
irb> want_a_beer? 'Bud'
=> :no
irb> want_a_beer? 'Bud Light'
=> :no
irb> want_a_beer? 'Coopers Pale Ale'
=> :probably
irb> want_a_beer? 'Stella Artois'
=> :probably
class Color
def more_blue?
b > r && b > g
end
!
def more_red?
r > b && r > g
end
!
def more_green?
g > r && g > b
end
end
def describe_color(color)
case color
when proc {|color|
color.more_blue? }
"blueish"
when proc {|color|
color.more_red? }
"reddish"
when proc {|color|
color.more_green? }
"greenish"
else
"pretty"
end
end
class Color
def more_blue?
b > r && b > g
end
!
def more_red?
r > b && r > g
end
!
def more_green?
g > r && g > b
end
end
def describe_color(color)
case color
when proc {|color|
color.more_blue? }
"blueish"
when proc {|color|
color.more_red? }
"reddish"
when proc {|color|
color.more_green? }
"greenish"
else
"pretty"
end
end
irb> describe_color Color::RED
=> "reddish"
irb> describe_color Color::GREEN
=> "greenish"
irb> describe_color Color.new(0xCC,0x11,0xFF)
=> "blueish"
irb> describe_color Color::CYAN
=> "pretty"
class Color
def more_blue?
b > r && b > g
end
!
def more_red?
r > b && r > g
end
!
def more_green?
g > r && g > b
end
end
def describe_color(color)
case color
when proc {|color|
color.more_blue? }
"blueish"
when proc {|color|
color.more_red? }
"reddish"
when proc {|color|
color.more_green? }
"greenish"
else
"pretty"
end
end
class Color
def more_blue?
b > r && b > g
end
!
def more_red?
r > b && r > g
end
!
def more_green?
g > r && g > b
end
end
def describe_color(color)
case color
when :more_blue?.to_proc
"blueish"
when :more_red?.to_proc
"reddish"
when :more_green?.to_proc
"greenish"
else
"pretty"
end
end
===“case equality operator”
===“threequals”
case object
when case1
do_something
when case2
do_another_thing
else
do_something_else
end
object
case1
do_something
case2
do_another_thing
else
do_something_else
end
!
if case1 === object
do_something
elsif case2 === object
do_another_thing
else
do_something_else
end
class Range
def ===(value)
self.include?(value)
end
end
class Module
def ===(object)
object.is_a?(self)
end
end
class Regexp
def ===(string)
if self =~ string
true
else
false
end
end
end
class Proc
def ===(object)
self.call(object)
end
end
class Object
def ===(other)
self == other
end
end
def somegem_adapter
case OtherGem::VERSION
when version("< 1.0")
OtherGemAdapter::Prerelease.new
when version([">= 1.0", "< 2.0"])
OtherGemAdapter::Version1x.new
when version(">= 2.0")
OtherGemAdapter::Current.new
end
end
def somegem_adapter
case OtherGem::VERSION
when version("< 1.0")
OtherGemAdapter::Prerelease.new
when version([">= 1.0", "< 2.0"])
OtherGemAdapter::Version1x.new
when version(">= 2.0")
OtherGemAdapter::Current.new
end
end
def somegem_adapter
case OtherGem::VERSION
when version("< 1.0")
OtherGemAdapter::Prerelease.new
when version([">= 1.0", "< 2.0"])
OtherGemAdapter::Version1x.new
when version(">= 2.0")
OtherGemAdapter::Current.new
end
end
def somegem_adapter
case OtherGem::VERSION
when version("< 1.0")
OtherGemAdapter::Prerelease.new
when version([">= 1.0", "< 2.0"])
OtherGemAdapter::Version1x.new
when version(">= 2.0")
OtherGemAdapter::Current.new
end
end
def somegem_adapter
case OtherGem::VERSION
when version("< 1.0")
OtherGemAdapter::Prerelease.new
when version([">= 1.0", "< 2.0"])
OtherGemAdapter::Version1x.new
when version(">= 2.0")
OtherGemAdapter::Current.new
end
end
def somegem_adapter
case OtherGem::VERSION
when version("< 1.0")
OtherGemAdapter::Prerelease.new
when version([">= 1.0", "< 2.0"])
OtherGemAdapter::Version1x.new
when version(">= 2.0")
OtherGemAdapter::Current.new
end
end
def somegem_adapter
case OtherGem::VERSION
when version("< 1.0")
OtherGemAdapter::Prerelease.new
when version([">= 1.0", "< 2.0"])
OtherGemAdapter::Version1x.new
when version(">= 2.0")
OtherGemAdapter::Current.new
end
end
def somegem_adapter
case OtherGem::VERSION
when version("< 1.0")
OtherGemAdapter::Prerelease.new
when version([">= 1.0", "< 2.0"])
OtherGemAdapter::Version1x.new
when version(">= 2.0")
OtherGemAdapter::Current.new
end
end
class VersionMatcher <
Struct.new(:operator, :req_version)
def ===(version)
case operator
when "="
version == req_version
when ">"
version > req_version
when "<"
version < req_version
when ">="
version >= req_version
when "<="
version <= req_version
else
false
end
end
end
class VersionMatcher <
Struct.new(:operator, :req_version)
def ===(version)
case operator
when "="
version == req_version
when ">"
version > req_version
when "<"
version < req_version
when ">="
version >= req_version
when "<="
version <= req_version
else
false
end
end
end
class VersionMatcher <
Struct.new(:operator, :req_version)
def ===(version)
case operator
when "="
version == req_version
when ">"
version > req_version
when "<"
version < req_version
when ">="
version >= req_version
when "<="
version <= req_version
else
false
end
end
end
class VersionMatcher <
Struct.new(:operator, :req_version)
def ===(version)
case operator
when "="
version == req_version
when ">"
version > req_version
when "<"
version < req_version
when ">="
version >= req_version
when "<="
version <= req_version
else
false
end
end
end
class VersionMatcher <
Struct.new(:operator, :req_version)
def ===(version)
case operator
when "="
version == req_version
when ">"
version > req_version
when "<"
version < req_version
when ">="
version >= req_version
when "<="
version <= req_version
else
false
end
end
end
class VersionMatcher::All <
Struct.new(:version_matchers)
!
def ===(version)
version_matchers
.all? {|matcher| matcher === version }
end
!
end
class VersionMatcher::All <
Struct.new(:version_matchers)
!
def ===(version)
version_matchers
.all? {|matcher| matcher === version }
end
!
end
class VersionMatcher::All <
Struct.new(:version_matchers)
!
def ===(version)
version_matchers
.all? {|matcher| matcher === version }
end
!
end
class VersionMatcher::All <
Struct.new(:version_matchers)
!
def ===(version)
version_matchers
.all? {|matcher| matcher === version }
end
!
end
class VersionMatcher::All <
Struct.new(:version_matchers)
!
def ===(version)
version_matchers
.all? {|matcher| matcher === version }
end
!
end
def version(requirements)
case requirements
when String
op, req_version = requirements.split
VersionMatcher.new(op, req_version)
when Array
matchers =
requirements.map {|r| version(r)}
VersionMatcher::All.new(matchers)
end
end
def version(requirements)
case requirements
when String
op, req_version = requirements.split
VersionMatcher.new(op, req_version)
when Array
matchers =
requirements.map {|r| version(r)}
VersionMatcher::All.new(matchers)
end
end
def version(requirements)
case requirements
when String
op, req_version = requirements.split
VersionMatcher.new(op, req_version)
when Array
matchers =
requirements.map {|r| version(r)}
VersionMatcher::All.new(matchers)
end
end
def version(requirements)
case requirements
when String
op, req_version = requirements.split
VersionMatcher.new(op, req_version)
when Array
matchers =
requirements.map {|r| version(r)}
VersionMatcher::All.new(matchers)
end
end
def somegem_adapter
case OtherGem::VERSION
when version("< 1.0")
OtherGemAdapter::Prerelease.new
when version([">= 1.0", "< 2.0"])
OtherGemAdapter::Version1x.new
when version(">= 2.0")
OtherGemAdapter::Current.new
end
end
def somegem_adapter
case OtherGem::VERSION
when version("< 1.0")
OtherGemAdapter::Prerelease.new
when version([">= 1.0", "< 2.0"])
OtherGemAdapter::Version1x.new
when version(">= 2.0")
OtherGemAdapter::Current.new
end
end
def somegem_adapter
case OtherGem::VERSION
when VersionMatcher.new("<", "1.0")
OtherGemAdapter::Prerelease.new
when version([">= 1.0", "< 2.0"])
OtherGemAdapter::Version1x.new
when version(">= 2.0")
OtherGemAdapter::Current.new
end
end
def somegem_adapter
case OtherGem::VERSION
when VersionMatcher.new("<", "1.0")
OtherGemAdapter::Prerelease.new
when version([">= 1.0", "< 2.0"])
OtherGemAdapter::Version1x.new
when version(">= 2.0")
OtherGemAdapter::Current.new
end
end
def somegem_adapter
case OtherGem::VERSION
when VersionMatcher.new("<", "1.0")
OtherGemAdapter::Prerelease.new
when VersionMatcher::All.new([
version(">= 1.0"),
version("< 2.0")
])
OtherGemAdapter::Version1x.new
when version(">= 2.0")
OtherGemAdapter::Current.new
end
end
def somegem_adapter
case OtherGem::VERSION
when VersionMatcher.new("<", "1.0")
OtherGemAdapter::Prerelease.new
when VersionMatcher::All.new([
version(">= 1.0"),
version("< 2.0")
])
OtherGemAdapter::Version1x.new
when version(">= 2.0")
OtherGemAdapter::Current.new
end
end
def somegem_adapter
case OtherGem::VERSION
when VersionMatcher.new("<", "1.0")
OtherGemAdapter::Prerelease.new
when VersionMatcher::All.new([
VersionMatcher.new(">=", "1.0"),
VersionMatcher.new("<" , "2.0")
])
OtherGemAdapter::Version1x.new
when version(">= 2.0")
OtherGemAdapter::Current.new
end
end
def somegem_adapter
case OtherGem::VERSION
when VersionMatcher.new("<", "1.0")
OtherGemAdapter::Prerelease.new
when VersionMatcher::All.new([
VersionMatcher.new(">=", "1.0"),
VersionMatcher.new("<" , "2.0")
])
OtherGemAdapter::Version1x.new
when version(">= 2.0")
OtherGemAdapter::Current.new
end
end
def somegem_adapter
case OtherGem::VERSION
when VersionMatcher.new("<", "1.0")
OtherGemAdapter::Prerelease.new
when VersionMatcher::All.new([
VersionMatcher.new(">=", "1.0"),
VersionMatcher.new("<" , "2.0")
])
OtherGemAdapter::Version1x.new
when VersionMatcher.new(">=", "2.0")
OtherGemAdapter::Current.new
end
end
def somegem_adapter
case OtherGem::VERSION
when VersionMatcher.new("<", "1.0")
OtherGemAdapter::Prerelease.new
when VersionMatcher::All.new([
VersionMatcher.new(">=", "1.0"),
VersionMatcher.new("<" , "2.0")
])
OtherGemAdapter::Version1x.new
when VersionMatcher.new(">=", "2.0")
OtherGemAdapter::Current.new
end
end
def somegem_adapter
OtherGem::VERSION
VersionMatcher.new("<", "1.0")
OtherGemAdapter::Prerelease.new
VersionMatcher::All.new([
VersionMatcher.new(">=", "1.0"),
VersionMatcher.new("<" , "2.0")
])
OtherGemAdapter::Version1x.new
VersionMatcher.new(">=", "2.0")
OtherGemAdapter::Current.new
end
end
def somegem_adapter
!
if VersionMatcher.new("<", "1.0") 
=== OtherGem::VERSION
OtherGemAdapter::Prerelease.new
elsif VersionMatcher::All.new([
VersionMatcher.new(">=", "1.0"),
VersionMatcher.new("<" , "2.0")
]) 
=== OtherGem::VERSION
OtherGemAdapter::Version1x.new
elsif VersionMatcher.new(">=", "2.0") 
=== OtherGem::VERSION
OtherGemAdapter::Current.new
end
!
end
def somegem_adapter
!
if VersionMatcher.new("<", "1.0") 
=== OtherGem::VERSION
OtherGemAdapter::Prerelease.new
elsif VersionMatcher::All.new([
VersionMatcher.new(">=", "1.0"),
VersionMatcher.new("<" , "2.0")
]) 
=== OtherGem::VERSION
OtherGemAdapter::Version1x.new
elsif VersionMatcher.new(">=", "2.0") 
=== OtherGem::VERSION
OtherGemAdapter::Current.new
end
!
end
irb> OtherGem::VERSION = '0.9'
irb> somegem_adapter
=> #<OtherGemAdapter::Prerelease>
irb> OtherGem::VERSION = '1.0'
irb> somegem_adapter
=> #<OtherGemAdapter::Version1x>
irb> OtherGem::VERSION = '1.2'
irb> somegem_adapter
=> #<OtherGemAdapter::Version1x>
irb> OtherGem::VERSION = '2.0'
irb> somegem_adapter
=> #<OtherGemAdapter::Current>
irb> OtherGem::VERSION = '4.0'
irb> somegem_adapter
=> #<OtherGemAdapter::Current>
Thank you!

Contenu connexe

Dernier

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Dernier (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Ruby’s Magical case Statement

  • 3. There is Totally Such a Thing as Magic
  • 4. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301 handle_redirect(http_response) when 302 handle_redirect(http_response) when 303 handle_redirect(http_response) when 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 5. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301 handle_redirect(http_response) when 302 handle_redirect(http_response) when 303 handle_redirect(http_response) when 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 6. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301 handle_redirect(http_response) when 302 handle_redirect(http_response) when 303 handle_redirect(http_response) when 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 7. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301 handle_redirect(http_response) when 302 handle_redirect(http_response) when 303 handle_redirect(http_response) when 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 8. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301 handle_redirect(http_response) when 302 handle_redirect(http_response) when 303 handle_redirect(http_response) when 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 9. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301 handle_redirect(http_response) when 302 handle_redirect(http_response) when 303 handle_redirect(http_response) when 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 10. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301 handle_redirect(http_response) when 302 handle_redirect(http_response) when 303 handle_redirect(http_response) when 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 11. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301 handle_redirect(http_response) when 302 handle_redirect(http_response) when 303 handle_redirect(http_response) when 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 12. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301 handle_redirect(http_response) when 302 handle_redirect(http_response) when 303 handle_redirect(http_response) when 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 13. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301 handle_redirect(http_response) when 302 handle_redirect(http_response) when 303 handle_redirect(http_response) when 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 14. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301 handle_redirect(http_response) when 302 handle_redirect(http_response) when 303 handle_redirect(http_response) when 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 15. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301 handle_redirect(http_response) when 302 handle_redirect(http_response) when 303 handle_redirect(http_response) when 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 16. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301 handle_redirect(http_response) when 302 handle_redirect(http_response) when 303 handle_redirect(http_response) when 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 17. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301 handle_redirect(http_response) when 302 handle_redirect(http_response) when 303 handle_redirect(http_response) when 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 18. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301 handle_redirect(http_response) when 302 handle_redirect(http_response) when 303 handle_redirect(http_response) when 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 19. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301 handle_redirect(http_response) when 302 handle_redirect(http_response) when 303 handle_redirect(http_response) when 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 20. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301 handle_redirect(http_response) when 302 handle_redirect(http_response) when 303 handle_redirect(http_response) when 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 21. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301 handle_redirect(http_response) when 302 handle_redirect(http_response) when 303 handle_redirect(http_response) when 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 22. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301, 302, 303, 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 23. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301, 302, 303, 307 handle_redirect(http_response) when 404 handle_not_found(http_response) else handle_unknown_error(http_response) end end
  • 24. def handle_response(http_response) case http_response.status when 200 handle_success(http_response) when 301, 302, 303, 307 handle_redirect(http_response) when 404 handle_not_found(http_response) when 400...500 handle_client_error(http_response) when 500...600 handle_server_error(http_response) else handle_unknown_error(http_response) end end
  • 25. def nickname(first_name) case first_name when 'Abraham' nickname = 'Abe' when 'Abigail' nickname = 'Abby' when 'Christopher', 'Christian', 'Christina' nickname = 'Chris' # etc., etc. else nickname = first_name end nickname end
  • 26. def nickname(first_name) case first_name when 'Abraham' nickname = 'Abe' when 'Abigail' nickname = 'Abby' when 'Christopher', 'Christian', 'Christina' nickname = 'Chris' # etc., etc. else nickname = first_name end nickname end
  • 27. def nickname(first_name) case first_name when 'Abraham' nickname = 'Abe' when 'Abigail' nickname = 'Abby' when 'Christopher', 'Christian', 'Christina' nickname = 'Chris' # etc., etc. else nickname = first_name end nickname end
  • 28. def nickname(first_name) case first_name when 'Abraham' nickname = 'Abe' when 'Abigail' nickname = 'Abby' when 'Christopher', 'Christian', 'Christina' nickname = 'Chris' # etc., etc. else nickname = first_name end nickname end
  • 29. def nickname(first_name) case first_name when 'Abraham' nickname = 'Abe' when 'Abigail' nickname = 'Abby' when 'Christopher', 'Christian', 'Christina' nickname = 'Chris' # etc., etc. else nickname = first_name end nickname end
  • 30. def nickname(first_name) case first_name when 'Abraham' nickname = 'Abe' when 'Abigail' nickname = 'Abby' when 'Christopher', 'Christian', 'Christina' nickname = 'Chris' # etc., etc. else nickname = first_name end nickname end
  • 31. def nickname(first_name) case first_name when 'Abraham' nickname = 'Abe' when 'Abigail' nickname = 'Abby' when 'Christopher', 'Christian', 'Christina' nickname = 'Chris' # etc., etc. else nickname = first_name end nickname end
  • 32. def nickname(first_name) case first_name when 'Abraham' nickname = 'Abe' when 'Abigail' nickname = 'Abby' when 'Christopher', 'Christian', 'Christina' nickname = 'Chris' # etc., etc. else nickname = first_name end nickname end
  • 33. def nickname(first_name) case first_name when 'Abraham' nickname = 'Abe' when 'Abigail' nickname = 'Abby' when 'Christopher', 'Christian', 'Christina' nickname = 'Chris' # etc., etc. else nickname = first_name end nickname end
  • 34. def nickname(first_name) case first_name when 'Abraham' nickname = 'Abe' when 'Abigail' nickname = 'Abby' when 'Christopher', 'Christian', 'Christina' nickname = 'Chris' # etc., etc. else nickname = first_name end nickname end
  • 35. def nickname(first_name) case first_name when 'Abraham' nickname = 'Abe' when 'Abigail' nickname = 'Abby' when 'Christopher', 'Christian', 'Christina' nickname = 'Chris' # etc., etc. else nickname = first_name end nickname end
  • 36. def nickname(first_name) case first_name when 'Abraham' nickname = 'Abe' when 'Abigail' nickname = 'Abby' when 'Christopher', 'Christian', 'Christina' nickname = 'Chris' # etc., etc. else nickname = first_name end nickname end
  • 37. def nickname(first_name) case first_name when 'Abraham' nickname = 'Abe' when 'Abigail' nickname = 'Abby' when 'Christopher', 'Christian', 'Christina' nickname = 'Chris' # etc., etc. else nickname = first_name end nickname end irb> nickname 'Christopher' => "Chris" irb> nickname 'Abigail' => "Abby" irb> nickname 'Christina' => "Chris" irb> nickname 'Fabio' => "Fabio"
  • 38. def nickname(first_name) case first_name when 'Abraham' nickname = 'Abe' when 'Abigail' nickname = 'Abby' when 'Christopher', 'Christian', 'Christina' nickname = 'Chris' # etc., etc. else nickname = first_name end nickname end
  • 39. def nickname(first_name) case first_name when 'Abraham' nickname = 'Abe' when 'Abigail' nickname = 'Abby' when 'Christopher', 'Christian', 'Christina' nickname = 'Chris' # etc., etc. else nickname = first_name end nickname end
  • 40. def nickname(first_name) nickname = case first_name when 'Abraham' 'Abe' when 'Abigail' 'Abby' when 'Christopher', 'Christian', 'Christina' 'Chris' # etc., etc. else first_name end nickname end
  • 41. def nickname(first_name) nickname = case first_name when 'Abraham' 'Abe' when 'Abigail' 'Abby' when 'Christopher', 'Christian', 'Christina' 'Chris' # etc., etc. else first_name end nickname end
  • 42. def nickname(first_name) case first_name when 'Abraham' 'Abe' when 'Abigail' 'Abby' when 'Christopher', 'Christian', 'Christina' 'Chris' # etc., etc. else first_name end ! end
  • 43. class Color < Struct.new(:r,:g,:b) ! RED = Color.new( 0xFF, 0x00, 0x00 ) GREEN = Color.new( 0x00, 0xFF, 0x00 ) BLUE = Color.new( 0x00, 0x00, 0xFF ) CYAN = Color.new( 0x00, 0xFF, 0xFF ) MAGENTA = Color.new( 0xFF, 0x00, 0xFF ) YELLOW = Color.new( 0xFF, 0xFF, 0x00 ) ! end def primary?(color, mode) case color when Color::RED, Color::GREEN, Color::BLUE mode == :additive when Color::CYAN, Color::MAGENTA, Color::YELLOW mode == :subtractive else false end end
  • 44. class Color < Struct.new(:r,:g,:b) ! RED = Color.new( 0xFF, 0x00, 0x00 ) GREEN = Color.new( 0x00, 0xFF, 0x00 ) BLUE = Color.new( 0x00, 0x00, 0xFF ) CYAN = Color.new( 0x00, 0xFF, 0xFF ) MAGENTA = Color.new( 0xFF, 0x00, 0xFF ) YELLOW = Color.new( 0xFF, 0xFF, 0x00 ) ! end def primary?(color, mode) case color when Color::RED, Color::GREEN, Color::BLUE mode == :additive when Color::CYAN, Color::MAGENTA, Color::YELLOW mode == :subtractive else false end end irb> primary? Color::RED, :additive => true irb> primary? Color::RED, :subtractive => false irb> primary? Color::CYAN, :subtractive => true irb> primary? Color.new(0,0,255), :additive => true irb> primary? Color.new(0,127,255), :additive => false
  • 45. def local_search(query) case query when String specs_by_name(query) when Gem::Dependency search_by_dependency(query) when Gem::Specification, RemoteSpecification, LazySpecification, EndpointSpecification search_by_spec(query) else raise "You can't search for #{query}." end end
  • 46. def local_search(query) case query when String specs_by_name(query) when Gem::Dependency search_by_dependency(query) when Gem::Specification, RemoteSpecification, LazySpecification, EndpointSpecification search_by_spec(query) else raise "You can't search for #{query}." end end
  • 47. def local_search(query) case query when String specs_by_name(query) when Gem::Dependency search_by_dependency(query) when Gem::Specification, RemoteSpecification, LazySpecification, EndpointSpecification search_by_spec(query) else raise "You can't search for #{query}." end end
  • 48. def local_search(query) case query when String specs_by_name(query) when Gem::Dependency search_by_dependency(query) when Gem::Specification, RemoteSpecification, LazySpecification, EndpointSpecification search_by_spec(query) else raise "You can't search for #{query}." end end
  • 49. def local_search(query) case query when String specs_by_name(query) when Gem::Dependency search_by_dependency(query) when Gem::Specification, RemoteSpecification, LazySpecification, EndpointSpecification search_by_spec(query) else raise "You can't search for #{query}." end end
  • 50. def local_search(query) case query when String specs_by_name(query) when Gem::Dependency search_by_dependency(query) when Gem::Specification, RemoteSpecification, LazySpecification, EndpointSpecification search_by_spec(query) else raise "You can't search for #{query}." end end
  • 51. def local_search(query) case query when String specs_by_name(query) when Gem::Dependency search_by_dependency(query) when Gem::Specification, RemoteSpecification, LazySpecification, EndpointSpecification search_by_spec(query) else raise "You can't search for #{query}." end end
  • 52. def local_search(query) case query when String specs_by_name(query) when Gem::Dependency search_by_dependency(query) when Gem::Specification, RemoteSpecification, LazySpecification, EndpointSpecification search_by_spec(query) else raise "You can't search for #{query}." end end
  • 53. def local_search(query) case query when String specs_by_name(query) when Gem::Dependency search_by_dependency(query) when Gem::Specification, RemoteSpecification, LazySpecification, EndpointSpecification search_by_spec(query) else raise "You can't search for #{query}." end end
  • 54. def local_search(query) case query when String specs_by_name(query) when Gem::Dependency search_by_dependency(query) when Gem::Specification, RemoteSpecification, LazySpecification, EndpointSpecification search_by_spec(query) else raise "You can't search for #{query}." end end
  • 55. def want_a_beer?(beer_type) case beer_type when /^Sierra Nevada|IPA/ :yes when /V(ictoria)? ?B(itter)?/, /Bud(weiser)?/ :no else :probably end end
  • 56. def want_a_beer?(beer_type) case beer_type when /^Sierra Nevada|IPA/ :yes when /V(ictoria)? ?B(itter)?/, /Bud(weiser)?/ :no else :probably end end
  • 57. def want_a_beer?(beer_type) case beer_type when /^Sierra Nevada|IPA/ :yes when /V(ictoria)? ?B(itter)?/, /Bud(weiser)?/ :no else :probably end end
  • 58. def want_a_beer?(beer_type) case beer_type when /^Sierra Nevada|IPA/ :yes when /V(ictoria)? ?B(itter)?/, /Bud(weiser)?/ :no else :probably end end
  • 59. def want_a_beer?(beer_type) case beer_type when /^Sierra Nevada|IPA/ :yes when /V(ictoria)? ?B(itter)?/, /Bud(weiser)?/ :no else :probably end end irb> want_a_beer? 'Sierra Nevada Pale Ale' => :yes irb> want_a_beer? 'Sierra Nevada Torpedo IPA' => :yes irb> want_a_beer? 'Mountain Goat IPA' => :yes irb> want_a_beer? 'Victoria Bitter' => :no irb> want_a_beer? 'VB' => :no irb> want_a_beer? 'V Bitter' => :no irb> want_a_beer? 'Budweiser' => :no irb> want_a_beer? 'Bud' => :no irb> want_a_beer? 'Bud Light' => :no irb> want_a_beer? 'Coopers Pale Ale' => :probably irb> want_a_beer? 'Stella Artois' => :probably
  • 60. class Color def more_blue? b > r && b > g end ! def more_red? r > b && r > g end ! def more_green? g > r && g > b end end def describe_color(color) case color when proc {|color| color.more_blue? } "blueish" when proc {|color| color.more_red? } "reddish" when proc {|color| color.more_green? } "greenish" else "pretty" end end
  • 61. class Color def more_blue? b > r && b > g end ! def more_red? r > b && r > g end ! def more_green? g > r && g > b end end def describe_color(color) case color when proc {|color| color.more_blue? } "blueish" when proc {|color| color.more_red? } "reddish" when proc {|color| color.more_green? } "greenish" else "pretty" end end irb> describe_color Color::RED => "reddish" irb> describe_color Color::GREEN => "greenish" irb> describe_color Color.new(0xCC,0x11,0xFF) => "blueish" irb> describe_color Color::CYAN => "pretty"
  • 62. class Color def more_blue? b > r && b > g end ! def more_red? r > b && r > g end ! def more_green? g > r && g > b end end def describe_color(color) case color when proc {|color| color.more_blue? } "blueish" when proc {|color| color.more_red? } "reddish" when proc {|color| color.more_green? } "greenish" else "pretty" end end
  • 63. class Color def more_blue? b > r && b > g end ! def more_red? r > b && r > g end ! def more_green? g > r && g > b end end def describe_color(color) case color when :more_blue?.to_proc "blueish" when :more_red?.to_proc "reddish" when :more_green?.to_proc "greenish" else "pretty" end end
  • 64.
  • 67. case object when case1 do_something when case2 do_another_thing else do_something_else end
  • 69. ! if case1 === object do_something elsif case2 === object do_another_thing else do_something_else end
  • 72. class Regexp def ===(string) if self =~ string true else false end end end
  • 75. def somegem_adapter case OtherGem::VERSION when version("< 1.0") OtherGemAdapter::Prerelease.new when version([">= 1.0", "< 2.0"]) OtherGemAdapter::Version1x.new when version(">= 2.0") OtherGemAdapter::Current.new end end
  • 76. def somegem_adapter case OtherGem::VERSION when version("< 1.0") OtherGemAdapter::Prerelease.new when version([">= 1.0", "< 2.0"]) OtherGemAdapter::Version1x.new when version(">= 2.0") OtherGemAdapter::Current.new end end
  • 77. def somegem_adapter case OtherGem::VERSION when version("< 1.0") OtherGemAdapter::Prerelease.new when version([">= 1.0", "< 2.0"]) OtherGemAdapter::Version1x.new when version(">= 2.0") OtherGemAdapter::Current.new end end
  • 78. def somegem_adapter case OtherGem::VERSION when version("< 1.0") OtherGemAdapter::Prerelease.new when version([">= 1.0", "< 2.0"]) OtherGemAdapter::Version1x.new when version(">= 2.0") OtherGemAdapter::Current.new end end
  • 79. def somegem_adapter case OtherGem::VERSION when version("< 1.0") OtherGemAdapter::Prerelease.new when version([">= 1.0", "< 2.0"]) OtherGemAdapter::Version1x.new when version(">= 2.0") OtherGemAdapter::Current.new end end
  • 80. def somegem_adapter case OtherGem::VERSION when version("< 1.0") OtherGemAdapter::Prerelease.new when version([">= 1.0", "< 2.0"]) OtherGemAdapter::Version1x.new when version(">= 2.0") OtherGemAdapter::Current.new end end
  • 81. def somegem_adapter case OtherGem::VERSION when version("< 1.0") OtherGemAdapter::Prerelease.new when version([">= 1.0", "< 2.0"]) OtherGemAdapter::Version1x.new when version(">= 2.0") OtherGemAdapter::Current.new end end
  • 82. def somegem_adapter case OtherGem::VERSION when version("< 1.0") OtherGemAdapter::Prerelease.new when version([">= 1.0", "< 2.0"]) OtherGemAdapter::Version1x.new when version(">= 2.0") OtherGemAdapter::Current.new end end
  • 83. class VersionMatcher < Struct.new(:operator, :req_version) def ===(version) case operator when "=" version == req_version when ">" version > req_version when "<" version < req_version when ">=" version >= req_version when "<=" version <= req_version else false end end end
  • 84. class VersionMatcher < Struct.new(:operator, :req_version) def ===(version) case operator when "=" version == req_version when ">" version > req_version when "<" version < req_version when ">=" version >= req_version when "<=" version <= req_version else false end end end
  • 85. class VersionMatcher < Struct.new(:operator, :req_version) def ===(version) case operator when "=" version == req_version when ">" version > req_version when "<" version < req_version when ">=" version >= req_version when "<=" version <= req_version else false end end end
  • 86. class VersionMatcher < Struct.new(:operator, :req_version) def ===(version) case operator when "=" version == req_version when ">" version > req_version when "<" version < req_version when ">=" version >= req_version when "<=" version <= req_version else false end end end
  • 87. class VersionMatcher < Struct.new(:operator, :req_version) def ===(version) case operator when "=" version == req_version when ">" version > req_version when "<" version < req_version when ">=" version >= req_version when "<=" version <= req_version else false end end end
  • 88. class VersionMatcher::All < Struct.new(:version_matchers) ! def ===(version) version_matchers .all? {|matcher| matcher === version } end ! end
  • 89. class VersionMatcher::All < Struct.new(:version_matchers) ! def ===(version) version_matchers .all? {|matcher| matcher === version } end ! end
  • 90. class VersionMatcher::All < Struct.new(:version_matchers) ! def ===(version) version_matchers .all? {|matcher| matcher === version } end ! end
  • 91. class VersionMatcher::All < Struct.new(:version_matchers) ! def ===(version) version_matchers .all? {|matcher| matcher === version } end ! end
  • 92. class VersionMatcher::All < Struct.new(:version_matchers) ! def ===(version) version_matchers .all? {|matcher| matcher === version } end ! end
  • 93. def version(requirements) case requirements when String op, req_version = requirements.split VersionMatcher.new(op, req_version) when Array matchers = requirements.map {|r| version(r)} VersionMatcher::All.new(matchers) end end
  • 94. def version(requirements) case requirements when String op, req_version = requirements.split VersionMatcher.new(op, req_version) when Array matchers = requirements.map {|r| version(r)} VersionMatcher::All.new(matchers) end end
  • 95. def version(requirements) case requirements when String op, req_version = requirements.split VersionMatcher.new(op, req_version) when Array matchers = requirements.map {|r| version(r)} VersionMatcher::All.new(matchers) end end
  • 96. def version(requirements) case requirements when String op, req_version = requirements.split VersionMatcher.new(op, req_version) when Array matchers = requirements.map {|r| version(r)} VersionMatcher::All.new(matchers) end end
  • 97. def somegem_adapter case OtherGem::VERSION when version("< 1.0") OtherGemAdapter::Prerelease.new when version([">= 1.0", "< 2.0"]) OtherGemAdapter::Version1x.new when version(">= 2.0") OtherGemAdapter::Current.new end end
  • 98. def somegem_adapter case OtherGem::VERSION when version("< 1.0") OtherGemAdapter::Prerelease.new when version([">= 1.0", "< 2.0"]) OtherGemAdapter::Version1x.new when version(">= 2.0") OtherGemAdapter::Current.new end end
  • 99. def somegem_adapter case OtherGem::VERSION when VersionMatcher.new("<", "1.0") OtherGemAdapter::Prerelease.new when version([">= 1.0", "< 2.0"]) OtherGemAdapter::Version1x.new when version(">= 2.0") OtherGemAdapter::Current.new end end
  • 100. def somegem_adapter case OtherGem::VERSION when VersionMatcher.new("<", "1.0") OtherGemAdapter::Prerelease.new when version([">= 1.0", "< 2.0"]) OtherGemAdapter::Version1x.new when version(">= 2.0") OtherGemAdapter::Current.new end end
  • 101. def somegem_adapter case OtherGem::VERSION when VersionMatcher.new("<", "1.0") OtherGemAdapter::Prerelease.new when VersionMatcher::All.new([ version(">= 1.0"), version("< 2.0") ]) OtherGemAdapter::Version1x.new when version(">= 2.0") OtherGemAdapter::Current.new end end
  • 102. def somegem_adapter case OtherGem::VERSION when VersionMatcher.new("<", "1.0") OtherGemAdapter::Prerelease.new when VersionMatcher::All.new([ version(">= 1.0"), version("< 2.0") ]) OtherGemAdapter::Version1x.new when version(">= 2.0") OtherGemAdapter::Current.new end end
  • 103. def somegem_adapter case OtherGem::VERSION when VersionMatcher.new("<", "1.0") OtherGemAdapter::Prerelease.new when VersionMatcher::All.new([ VersionMatcher.new(">=", "1.0"), VersionMatcher.new("<" , "2.0") ]) OtherGemAdapter::Version1x.new when version(">= 2.0") OtherGemAdapter::Current.new end end
  • 104. def somegem_adapter case OtherGem::VERSION when VersionMatcher.new("<", "1.0") OtherGemAdapter::Prerelease.new when VersionMatcher::All.new([ VersionMatcher.new(">=", "1.0"), VersionMatcher.new("<" , "2.0") ]) OtherGemAdapter::Version1x.new when version(">= 2.0") OtherGemAdapter::Current.new end end
  • 105. def somegem_adapter case OtherGem::VERSION when VersionMatcher.new("<", "1.0") OtherGemAdapter::Prerelease.new when VersionMatcher::All.new([ VersionMatcher.new(">=", "1.0"), VersionMatcher.new("<" , "2.0") ]) OtherGemAdapter::Version1x.new when VersionMatcher.new(">=", "2.0") OtherGemAdapter::Current.new end end
  • 106. def somegem_adapter case OtherGem::VERSION when VersionMatcher.new("<", "1.0") OtherGemAdapter::Prerelease.new when VersionMatcher::All.new([ VersionMatcher.new(">=", "1.0"), VersionMatcher.new("<" , "2.0") ]) OtherGemAdapter::Version1x.new when VersionMatcher.new(">=", "2.0") OtherGemAdapter::Current.new end end
  • 107. def somegem_adapter OtherGem::VERSION VersionMatcher.new("<", "1.0") OtherGemAdapter::Prerelease.new VersionMatcher::All.new([ VersionMatcher.new(">=", "1.0"), VersionMatcher.new("<" , "2.0") ]) OtherGemAdapter::Version1x.new VersionMatcher.new(">=", "2.0") OtherGemAdapter::Current.new end end
  • 108. def somegem_adapter ! if VersionMatcher.new("<", "1.0") === OtherGem::VERSION OtherGemAdapter::Prerelease.new elsif VersionMatcher::All.new([ VersionMatcher.new(">=", "1.0"), VersionMatcher.new("<" , "2.0") ]) === OtherGem::VERSION OtherGemAdapter::Version1x.new elsif VersionMatcher.new(">=", "2.0") === OtherGem::VERSION OtherGemAdapter::Current.new end ! end
  • 109. def somegem_adapter ! if VersionMatcher.new("<", "1.0") === OtherGem::VERSION OtherGemAdapter::Prerelease.new elsif VersionMatcher::All.new([ VersionMatcher.new(">=", "1.0"), VersionMatcher.new("<" , "2.0") ]) === OtherGem::VERSION OtherGemAdapter::Version1x.new elsif VersionMatcher.new(">=", "2.0") === OtherGem::VERSION OtherGemAdapter::Current.new end ! end irb> OtherGem::VERSION = '0.9' irb> somegem_adapter => #<OtherGemAdapter::Prerelease> irb> OtherGem::VERSION = '1.0' irb> somegem_adapter => #<OtherGemAdapter::Version1x> irb> OtherGem::VERSION = '1.2' irb> somegem_adapter => #<OtherGemAdapter::Version1x> irb> OtherGem::VERSION = '2.0' irb> somegem_adapter => #<OtherGemAdapter::Current> irb> OtherGem::VERSION = '4.0' irb> somegem_adapter => #<OtherGemAdapter::Current>