1
저는 VisualRuby에서 트위터가있는 작은 프로그램을 만들고 있습니다.
인증 정보를 넣을 곳
을 지금은이를 실행할 때 클릭
#!/usr/bin/ruby
require 'vrlib'
require 'twitter_oauth'
#make program output in real time so errors visible in VR.
STDOUT.sync = true
STDERR.sync = true
#everything in these directories will be included
my_path = File.expand_path(File.dirname(__FILE__))
require_all Dir.glob(my_path + "/bin/**/*.rb")
LoginWindow.new.show
내 LoginWindow.rb
이
require 'twitter_oauth'
class LoginWindow #(change name)
include GladeGUI
client = TwitterOAuth::Client.new(
:consumer_key => '****',
:consumer_secret => '****',
:token => '****-****',
:secret => '****'
)
def show()
load_glade(__FILE__) #loads file, glade/MyClass.glade into @builder
set_glade_all() #populates glade controls with insance variables (i.e. Myclass.label1)
show_window()
end
def button1__clicked(*argv)
if client.authorized?
puts "true"
end
end
end
그리고 마지막으로 내 창은 다음과 같습니다과 같습니다 : 그래서 여기 내 main.rb
의 모습입니다 로그인 버튼, VR은 이것을 내뱉습니다.
C:/Users/*/visualruby/Test/bin/LoginWindow.rb:22:in `button1__clicked': undefined local variable or method `client' for #<LoginWindow:0x3f56aa8>
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/vrlib-0.0.33/lib/GladeGUI.rb:146:in `call'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/vrlib-0.0.33/lib/GladeGUI.rb:146:in `block (3 levels) in parse_signals'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/vrlib-0.0.33/lib/GladeGUI.rb:331:in `call'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/vrlib-0.0.33/lib/GladeGUI.rb:331:in `main'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/vrlib-0.0.33/lib/GladeGUI.rb:331:in `show_window'
from C:/Users/*/visualruby/Test/bin/LoginWindow.rb:17:in `show'
from main.rb:14:in `<main>'
나는 client = Twitter....
을 LoginWindow
클래스 안에 넣어야한다고 생각하지 않지만 다른 곳에서는 생각할 수 없다. 이 문제를 해결하는 방법에 대한 아이디어가 있습니까?
아마도 인스턴스 변수에서 클라이언트를 변형해야합니다. initialize 메소드 내에서 TwitterOAuth를 호출 할 수 있습니다. –
@amalrikmaia 정확히 무엇을 의미합니까? 내부에 인스턴스 변수'@client'가있는 초기화 함수를 가지고 있다고 하시겠습니까? – Richard
_ 내부에 인스턴스 변수 @client가있는 초기화 함수가 있습니까? _ 예. –