search for: block_given

Displaying 20 results from an estimated 66 matches for "block_given".

2006 Jul 21
2
File.open behavior for ActiveRecord, to ensure save after manipulation?
File.open in core Ruby is nifty, in that it automagically closes the file when you''re done using/manipulating it. I''m wondering whether there''s something like that for ActiveRecord? So you can do: AR.find(23).open {|ar| ar.foo = ''bar'' ... } And ar.save would be called when the block closes. -- -Alder
2007 Oct 04
0
Prototyping the Dir class
...E'', buf, buf.size) == 0 if GetEnvironmentVariable(''HOME'', buf, buf.size) == 0 raise ArgumentError, ''USERPROFILE/HOME not set'' end end dir = buf.unpack("Z*")[0] end if block_given? begin buf = 0.chr * MAX_PATH if GetCurrentDirectory(buf.length, buf) == 0 raise ArgumentError, get_last_error else # MSDN says the drive letter could be dropped, # and that GetFullPathName should be c...
2006 Sep 29
1
yielding consecutive values
...x: lib/mocha/expectation.rb =================================================================== --- lib/mocha/expectation.rb (revision 62) +++ lib/mocha/expectation.rb (working copy) @@ -217,7 +217,12 @@ def invoke @invoked += 1 - yield(*@parameters_to_yield) if yield? and block_given? + if yield? and block_given? + params = @parameters_to_yield.collect do |element| + element.is_a?(Proc) ? element.call : element + end + yield(*params) + end @return_value.is_a?(Proc) ? @return_value.call : @return_value end This test passes a...
2006 Sep 29
2
multiyield
...@multiyield = true + @parameters_to_yield = parameters + self + end # :call-seq: returns(value) -> expectation # :call-seq: returns(*values) -> expectation @@ -218,6 +228,7 @@ def invoke @invoked += 1 yield(*@parameters_to_yield) if yield? and block_given? + @parameters_to_yield.each { |element| yield(element) } if multiyield? and block_given? @return_value.is_a?(Proc) ? @return_value.call : @return_value end Is this already in the framework and I missed it?
2006 Aug 18
10
TreeCtrl update
...puts "Name: #{tree_ctrl.get_item_text(node_id)}\t\tCookie: #{cookie}" end def traverse_tree(tree_ctrl,root_node,cookie=0,&block) if cookie == 0 ret = tree_ctrl.get_first_child(root_node) else ret = tree_ctrl.get_next_child(root_node,cookie) end if ret[0].is_ok if block_given? yield(ret[0],ret[1]) end traverse_tree(tree_ctrl,ret[0],0,&block) end ret_sib = tree_ctrl.get_next_sibling(root_node) if ret_sib.is_ok if block_given? yield(ret_sib,cookie) end traverse_tree(tree_ctrl,ret_sib,0,&block) end end Sean ________...
2007 May 23
2
rspec mocha and controller specs without integrated_views
...ty to choose a mocking framework is great as I prefer mocha, but I am have problems. On my controller specs, I am forced to ''integrate_views'' as the following code below shows you, the mocking of views is rspec specific. See stub! versus mocha''s stub unless block_given? unless integrate_views? @template.stub!(:file_exists?).and_return(true) @template.should_receive(:render_template).any_number_of_times.and_return(true) { |*args| @first_render ||= args[2] } @template.stub!(:find...
2006 Sep 14
2
Possiible Bug ? indexWriter#doc_count countsdeleted docs after #commit
...is deleted then added again, but doesn''t show up in my searches. A #doc_count on the writer before and after #add_document shows that the index is 1 document larger, but I still cant #search for the updated doc. What do you think about having #add_document "yield" the doc_id if block_given? Neville
2006 Jan 22
3
Balancing relevancy and recentness
I was wondering if there was a good way to either balance the relevancy score with recentness of matching documents- or include the recentness in the score somehow? Thanks, Ben -- Posted via http://www.ruby-forum.com/.
2006 Sep 22
2
foo.expects(:blah).returns(10).then(11) syntax
...end def raises(exception = RuntimeError, message = nil) - @return_value = lambda{ raise exception, message } + return_value << lambda{ raise exception, message } self end def invoke @invoked += 1 yield(*@parameters_to_yield) if yield? and block_given? - @return_value.is_a?(Proc) ? @return_value.call : @return_value + this_return = return_value.size > 1 ? return_value.shift : return_value.first + this_return.is_a?(Proc) ? this_return.call : this_return end def verify
2006 May 21
6
Possible problems with EventLog#write
Hi, I''ve got EventLog#write and EventLog.add_event_source methods done. Well, I *think* they''re done, but I can''t get the data (text) to work properly, and I''m not sure if it''s a bug in my .mc file, the add_event_source method, the write method, or just a goof in my test file. The source, category and event id seem to be ok. However, the
2007 Sep 05
1
AAF and DRb with highlighting
...ery, hit, :field => :body, :pre_tag => "<strong>", :post_tag => "</strong>", :num_excerpts => 1) result[:article] = article result[:score] = score results.push result end unless query.nil? return block_given? ? total_hits : [total_hits, results] end -- Posted via http://www.ruby-forum.com/.
2006 Apr 04
1
ActiveRecord object
...t;links", links will be an array. class User < ActiveRecord::Base attr :links end and now, I want links to be an array, so I do class User < ActiveRecord::base attr:links def initialize(attributes) super(attributes) @links = Array.new yield self if block_given? end end but then I do users = User.find(:all) user = users[0] user.links.find {|x| x == "foo"} and it gives me an error because it says that user.links is null What is my mistake? I just need the attribute links to be an array Rodrigo Dominguez Iplan Networks...
2006 Jan 14
1
Adjusting scores
One other mod to Ferret I''ve found useful is to add the following line at the top of the each_hit() block in Search::IndexSearcher.search: score = yield( doc, score ) if block_given? This allows a block attached to a search call to adjust document scores before documents are sorted, based on some (possibly dynamic) numerical factors associated with the document, e.g. the number and importance of incoming links to the document (Google''s PageRank).
2006 May 02
1
Converting rb_protect + ruby_stop to pure Ruby
Hi, Within process.c, in the fork method, there''s this bit of code: if(rb_block_given_p()){ int status; rb_protect(rb_yield, Qundef, &status); ruby_stop(status); } I translated that as this: if block_given? status = 0 begin yield rescue Exception status = -1 # Any non-zero result is failure end exit(status) end Is there a way to...
2007 Aug 07
2
stubs which yield and return
Is there any reason why a stub couldn''t both yield and return? I''m looking for a way to mock out a class I''ve made named "AnonymousClass": class AnonymousClass def initialize(&blk) @klass = Class.new @klass.instance_eval(&blk) if block_given? end def new @klass.new end def evaluate(&blk) @klass.instance_eval(&blk) end attr_reader :klass alias_method :class, :klass end One of the behaviours of the AnonymousClass is that new can take a block, and eval the block in the anonymous class, represen...
2007 Oct 07
22
Differences in execution between console and app
class AppointmentBook < ActiveRecord::Base has_many :appointments def lookup(date, look_ahead = 27) return nil unless block_given? (date..date + look_ahead).each do |date| yield(date, appointments.find_all_by_date(date)) end end end The line with yield is throwing the error: undefined method ''each'' for #<Date: 4908761/2,0,2299161> A YAML dump of date yields: >>> DATE: --- 2...
2007 Jan 09
1
assert_redirected_to not working as expected
...post "/account/signup", :login => login, :email => email, :password => password, :confirm_password => confirm_password end end def enter_site(name) open_session do |session| session.extend(BrowsingTestDSL) session.name = name yield session if block_given? end end end === I''m on Windows and am running the test using this command: > ruby test/integration/authentication_test.rb - n test_successful_signup Resulting in: "Expected response to be a <:redirect>, but was <200>" Running live produces the desired...
2006 Dec 30
0
[811] trunk/wxsugar/lib/wx_sugar/layout.rb: Yield the sizer rather than the underlying parent to an ''arrange'' block
...+113,7 @@ </span><span class="cx"> end </span><span class="cx"> @padding = layout[:padding] if layout[:padding] </span><span class="cx"> @current_sizer = a_sizer </span><del>- yield(self) if block_given? </del><ins>+ yield(a_sizer) if block_given? </ins><span class="cx"> self.set_sizer(a_sizer) </span><span class="cx"> end </span><span class="cx"> end </span></span></pre> </div> &...
2006 Jun 15
4
testing with transactions
...(esp. with connection_adapters and wrapping this all up as a plugin perhaps). Something in the way of: # Wrap a block in a transaction. Returns result of block. def transaction(start_db_transaction = true) transaction_open = false savepoint_open = false savepoint_name = nil begin if block_given? if start_db_transaction begin_db_transaction transaction_open = true else savepoint_name = create_savepoint savepoint_open = true end yield end rescue Exception => database_transaction_rollback if transaction_open transacti...
2008 May 18
2
Pure win32-thread library?
...9;'L'', ''L''){ |args| block = args.pop block.call(args) ReleaseMutex(@@mutex) } attr_reader :thread_id def initialize(*args, &block) raise ArgumentError, ''block must be provided'' unless block_given? args.push(block) thread_id = [0].pack(''L'') dwArgs = nil # What should this be? @thread = CreateThread( nil, # Handle cannot be inherited 0, # Default stack size WinThreadFunc...