Displaying 20 results from an estimated 29 matches for "instance_of".
2007 Mar 06
15
mocking missing methods
Hi folks.
So I''m using mocha on a ruby project, and I really like it. One thing
I''ve noticed is that it can be a bit "surprising" when I''m mocking
methods that don''t exist on an object, and I think there''s an easyish fix.
At the moment, you use sheep = mock() to create a mock sheep. What I''d
like to do is something like sheep =
2007 Feb 24
3
Spec failing [Possible Bug with kind_of? and instance_of?]
I have a spec which is failing, but I just can''t say why. Maybe I''m
missing something painfully obvious?
Here is the pastie of the results & the spec:
http://pastie.caboo.se/42626
The spec to look for is "should have an array of users" I''ve printed
out ("puts''ed") to the terminal the fact that the values are
*opposite* to what
2012 Jan 21
4
why doesn't an instance of Object get Class's new instance method?
"Object is the root of Ruby''s class hierarchy. Its methods are
available to all classes unless explicitly overridden."
Wouldn''t Class class be at the root of the class hierarchy?
After all, look at this:
1.9.2p290 :006 > Object.instance_of? Class
=> true
Object is an instance of class, after all we can use one of Class''
instance methods on Object:
1.9.2p290 :017 > Object.new
=> #<Object:0x007faad047ecd0>
But Class is not instance of Object:
1.9.2p290 :007 > Class.instance_of? Object
=> false
1.9...
2010 Aug 29
4
Wrong class being returned in association
...w
@user = User.find(params[:user_id])
@conversation = @user.conversations.find(params[:id])
debugger
end
end
After requesting conversations#show, go to debug console and:
User.class.object_id
=> 116350
@conversation.users.first.class.object_id
=> 33660870
@conversation.users.first.instance_of? User
=> true # Right
Then leave debugging and request the page again:
User.class.object_id
=> 116350
@conversation.users.first.class.object_id
=> 36497930
@conversation.users.first.instance_of? User
=> true # Right
And then, request the page again:
User.class.object_id
=> 11...
2006 Nov 19
2
underscores, sugar, and more and more bugs
...ing several benefits including:
# more clarity in the API
# a place to put meaningful rdoc
# a potential formal plugin point
2. Change should_be to ONLY handle arbitrary predicates (not serve as
an alias for should_equal):
subject.should_be :empty => passes if subject.empty?
subject.should_be :instance_of, SomeClass => passes if
subject.instance_of? SomeClass
etc...
In my opinion (feel free to disagree), this actually makes these
examples more readable. Consider these two:
@bdd_framework.should_be_adopted_quickly #current
@bdd_framework.should_be :adopted_quickly #proposed
In my view, these re...
2006 Nov 19
6
artificial sugar causes cancer
...ing several benefits including:
# more clarity in the API
# a place to put meaningful rdoc
# a potential formal plugin point
2. Change should_be to ONLY handle arbitrary predicates (not serve as
an alias for should_equal):
subject.should_be :empty => passes if subject.empty?
subject.should_be :instance_of, SomeClass => passes if
subject.instance_of? SomeClass
etc...
In my opinion (feel free to disagree), this actually makes these
examples more readable. Consider these two:
@bdd_framework.should_be_adopted_quickly #current
@bdd_framework.should_be :adopted_quickly #proposed
In my view, these re...
2013 Aug 27
11
Why NaN.class throws NameError ?
Here is my sample code:
class Foo
Bar = 10
end
Foo::Bar # => 10
Foo::Bar.class # => Fixnum
10.class # => Fixnum
Float::NAN # => NaN
Float::NAN.class # => Float
NaN.class
# uninitialized constant NaN (NameError)
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To
2005 Dec 20
2
Null Text Fields
I tend to allow nulls in cases where the value is unknown, even if
it''s a text/varchar field. RoR seems to push empty strings into these
fields. Is there any way to get RoR to use NULL vice '''' if the input
box is empty?
Thanks!
- Ian
2006 Sep 05
2
Mongrel and umask for uploaded files
...e.umask(022)'' inside
environment.rb but that doesn''t make a difference.
To handle uploads, I have a resource model which does the following in
the before_create filter:
def before_create
return FileUtils.copy( @uploaded_file.local_path,
self.path_to_file) if @uploaded_file.instance_of?(Tempfile)
# else
File.open(self.path_to_file, "w") { |f| f.write(@uploaded_file.read) }
end
If anyone has any other hints for how to change the umask, please let
me know, this is driving me crazy! Thanks,
Mike
2006 Jun 09
8
[how can i delete a file system..please help]
Hi,
I''m trying to delete a file system (<xml_26548975.xml>)
File.delete("xml_26548975.xml")
But I get this error:
"Permission denied - ./script/../config/../uploads/xml_26548975.xml".
Why?
--
Cheers,
ioana k&a
http://boulangerie.wordpress.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
2007 May 24
3
Exception Notification Plugin Question
Hi,
I have two questions re the Exception Notifier plugin (i.e. which you
install via "ruby script/plugin install exception_notification")
Q1 - In it''s current setup (where it uses /public/500.html) is it possible
to remove the "Status: 500 Internal Server Error Content-Type: text/html"
text which seems to mysteriously get place at the top of the page?
Q2 -
2006 Jun 20
2
Problem with "can''t dump anonymous class Class"
...Document below,
it works fine.
Here is the relevant code:
** Models **
class Document < ActiveRecord::Base
attr_accessor :uploaded_file
def after_create
if !File.exists?(File.dirname(self.file_path))
Dir.mkdir(File.dirname(self.file_path))
end
if @uploaded_file.instance_of?(Tempfile)
FileUtils.copy(@uploaded_file.local_path, self.file_path)
else
File.open(self.file_path, "wb") { |f| f.write(@uploaded_file.read) }
end
end
def after_destroy
if File.exists?(self.file_path)
File.delete(self.file_path)
end
end
def...
2006 Mar 12
2
Find all the methods on a object in an irb session?
How can I find all the methods on an object from withing irb?
Thanks,
Joe
2006 Nov 22
2
.class call to the mock object (or any existing methods)
Hi
I run into problem trying to set expectations for the mockobject.class
method, I had to undefine a method before I could set some expectation. Is
there any better way of doing it?
object = mock()
....
klass = class <<object; self; end
klass.send(:undef_method, "class") # I had to do this because Mocha
utilizes "method_missing(symbol, *arguments, &block) "
2007 Aug 19
4
describing a mock_model as being an instance
Is there a built-in way of describing a mock_model as being an instance, beyond
stubbing the eval("Object.methods - Object.new.methods") methods to throw
NoMethodErrors?
Edward
2006 Jun 08
1
Permissions on uploaded files, TinyFile
Hi, im getting a little trouble with this, im using TinyFile as the
example to upload files
http://wiki.rubyonrails.com/rails/pages/TinyFile/versions/20
All goes well but the files uploaded are saved with permissions 600
(linux) and in the case of images arent showed on the browser(but
uploaded and stored in the server without problems) i have to manually
ftp to the uploaded files folder and
2011 Dec 22
0
mongodb Map/reduce grouping
...fourth"=>{"id"=>"4",
"score"=>"4"},"fifth"=>{"id"=>"5", "score"=>"5"}}
temp ={"id"=>"10","score"=>"20"}
aTotalScore = 0
if @challenge.instance_of?Challenge
@challenge.tasks.each_with_index do |orgTasks,index|
aTotalScore += orgTasks.score.to_i
end
$wins["first"]["id"]= @challenge.user_id
$wins["first"]["score"]= aTotalScore
aTotalScore = 0
@challenge.chil...
2006 Aug 02
3
Upload forms--where is the file object?
Hi All,
I''ve been trying to create an upload form page that will take an
uploaded file, and save it to a directory on the server. I''ve tried
following a couple of posts on this list, and the HowTo from here:
http://wiki.rubyonrails.org/rails/pages/HowtoUploadFiles
Here is the code in my view:
<%= start_form_tag ( {:action => "upload"}, { :mulipart => true }
2006 May 24
0
Mongrel errors on file upload
.../1.8/gems/mongrel-0.3.11-mswin32/bin/mongrel_rails:228
C:/InstantRails-1.3/ruby/bin/mongrel_rails:18
Here''s my code.
------------ create_controller.rb --------------
class CreateController < ApplicationController
def index
end
def read_in
if params[:file_to_upload].instance_of?(Tempfile)
FileUtils.copy(params[:file_to_upload].local_path, "#{RAILS_ROOT}/public/sandbox1.xml")
@location_display = "Copied the Tempfile to sandbox1.xml"
else
File.open("#{RAILS_ROOT}/public/sandbox2.xml","w"){|f|
f.write(par...
2006 Jul 05
2
Serialized object behaves weird
Hi!
I got a class named EinsatzFilter which I serialized to session. Before
saving to session it works afterwards I keep getting the message:
"undefined method `to_s'' for #<Person:0x38c6ab8>". "Person" is a from
ActiveRecord::Base inherited class.
Code:
class EinsatzFilter
include ApplicationHelper
attr_reader :personen, :monat, :projekte, :kunde