From 9561b4bc8e0fee449af60f8957c7ea510e41b561 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Tue, 19 Feb 2013 10:15:52 -0600 Subject: [PATCH] Fix X11 proxy constant lookup under 1.9+ --- Library/Homebrew/requirements.rb | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/Library/Homebrew/requirements.rb b/Library/Homebrew/requirements.rb index f2d9dfeb8d..34273a0f39 100644 --- a/Library/Homebrew/requirements.rb +++ b/Library/Homebrew/requirements.rb @@ -109,19 +109,29 @@ class X11Dependency < Requirement class Proxy < self PACKAGES = [:libpng, :freetype, :fontconfig] - def self.for(name, *tags) - constant = name.capitalize - - if const_defined?(constant) - klass = const_get(constant) - else - klass = Class.new(self) do - def initialize(name, *tags) super end + class << self + def defines_const?(const) + if ::RUBY_VERSION >= "1.9" + const_defined?(const, false) + else + const_defined?(const) end - - const_set(constant, klass) end - klass.new(name, *tags) + + def for(name, *tags) + constant = name.capitalize + + if defines_const?(constant) + klass = const_get(constant) + else + klass = Class.new(self) do + def initialize(name, *tags) super end + end + + const_set(constant, klass) + end + klass.new(name, *tags) + end end end end